[code-quality] pylint can't deduce the type of an object

Paul Smith paul at mad-scientist.net
Fri Nov 28 21:57:28 CET 2014


Hi all; as mentioned in a previous post, I am looking into updating my
curring pylint (1.0.1) to newer pylint 1.4.0.

I've got one significant problem left and I'm not sure how to resolve
it: in the new pylint I'm seeing a number of errors like this:

  mymod.py:227: [E1101(no-member), MyMod.__str__] Instance of 'int' has no 'get_val' member

The code in question is something like:

  self.someobj.get_val()

The problem appears to be that pylint cannot tell the type of the object
stored in "someobj", so it assumes "int" and gives an error.  The value
of self.someobj is passed in via the constructor, and so this module
really _doesn't_ know the type.

I checked what pylint 1.0.1 is doing and it seems to be ignoring that
value altogether, so it doesn't give the above incorrect error but it
also doesn't complain if, for example, I change the call to
"self.someobj.getval()" (or any other non-existent method).

Can I do something to get pylint to understand this type?  If it cannot
figure it out automatically, is there some way I can hint or annotate
the type of this member so pylint will understand what it is?  Is there
a way to disable the "assume an int" processing and ignore unknown
members, like the old pylint did, without disabling E1101 altogether?

Pylint is run automatically as part of our static analysis tests so I
can't upgrade until I can get the new version to run clean.



More information about the code-quality mailing list