<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def endsbefore(self, other):
 """ Test if this range ends before `other`. `other` may be either range or scalar. This only takes the upper end of the ranges into consideration. If the scalar or the upper end of the given range is less than or equal to this range's upper end, ``True`` is returned. True True :param other: Range or scalar to test. :return: ``True`` if this range ends before `other`, otherwise ``False`` :raises TypeError: If `other` is of the wrong type. """


        if self.is_valid_range(other):
            if self.upper == other.upper:
                return not self.upper_inc or other.upper_inc
            elif self.upper_inf:
                return False
            elif other.upper_inf:
                return True
            else:
                return self.upper <= other.upper
        elif self.is_valid_scalar(other):
            return self.upper <= other
        else:
            raise TypeError(
                "Unsupported type to test for ends before '{}'".format(
                    other.__class__.__name__))