[Python-projects] Pylint error: E1101

Sylvain Thénault sylvain.thenault at logilab.fr
Tue Dec 11 09:45:27 CET 2007


On Mon, Dec 10, 2007 at 05:35:19PM -0600, Meding, Olaf wrote:
> 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 

I think the problem is that astng doesn't well understand __new__. Btw,
why are you not simply using __init__ here ?
-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
Python et calcul scientifique:           http://www.logilab.fr/science



More information about the Python-Projects mailing list