[Python-projects] pylint E1101 false positive
Daniel Drake
ddrake at brontes3d.com
Tue Dec 5 15:55:08 CET 2006
On Tue, 2006-12-05 at 09:55 +0100, Sylvain Thénault wrote:
> > import numarray as na
> > import numarray.random_array as nar
> > im16 = nar.randint(0, 256, 300).astype(na.UInt8)
> >
> > The above program causes pylint to complain:
> >
> > E1101: 3: Instance of 'int' has no 'astype' member
> >
> > This is with numarray-1.5.2. The randint function returns either a
> > numarray or an int. In this context it will only return a numarray
> > so .astype() is valid.
>
> ticket #3216
I have investigated further, based on your comments on the ticket. Your
suggestions actually seem to already happen: the warning won't be
flagged if the attribute is a member of any of the inferred values.
The problem instead seems to be that astng is only inferring "int" and
"YES" from that function, i.e. there is an ambiguity which it couldn't
resolve.
I believe the problem is that astng inference on overloaded operators
doesn't work. I might be wrong but nevertheless this is either the cause
of this bug, or a new bug :)
I am attaching a standalone program which demonstrates. The myarray
class overloads the * operator, astng could potentially infer that the *
operator now always returns a myarray but this doesn't seem to be the
case. pylint throws the E1101 warning.
If you remove the "* 2" then astng can correctly infer the return types
of "int" and "myarray" and pylint is happy.
--
Daniel Drake
Brontes Technologies, A 3M Company
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.py
Type: text/x-python
Size: 609 bytes
Desc: not available
Url : http://lists.logilab.org/pipermail/python-projects/attachments/20061205/5425e41b/attachment.py
More information about the Python-Projects
mailing list