[Python-projects] Pylint error: E1101

Meding, Olaf Olaf.Meding at bruker-axs.com
Tue Dec 11 00:35:19 CET 2007


Seems to me that the code below should not produce this error:
  [E1101, NoneFloat.__mul__] Instance of 'NoneFloat' has no 'value'
member

class NoneFloat(float):
    """ Convenience class to convert angle units from degrees to radians
        and vice versa.  Note that the value of an angle may be `None`.

        usage::
            angle = 30.0 * degrees  # convert to radians
            angle = None * degrees  # angle is still none
            angle = 3.14 / degrees  # convert to degrees
            angle = None / degrees  # angle is still `None`
            
            angle = 3.14 * radians  # express angle in radians

    """
    def __new__(cls, value):
        self = super(NoneFloat, cls).__new__(cls, value)
        self.value = value
        return self
    def __mul__(self, other):
        if other is None:
            return None
        return other * self.value
    def __rmul__(self, other):
        if other is None:
            return None
        return other * self.value
    def __div__(self, other):
        if other is None:
            return None
        return self.value / other
    def __rdiv__(self, other):
        if other is None:
            return None
        return other / self.value
degrees = NoneFloat(math.pi / 180.0)
radians = NoneFloat(1.0)
del NoneFloat  # remove from namespace 


Olaf


More information about the Python-Projects mailing list