[Python-projects] Suggestion about E1101 Instance of 'None' has no 'get' member
Barry Scott
barry.scott at onelan.co.uk
Wed Dec 13 12:51:51 CET 2006
Sylvain Thénault wrote:
> On Tuesday 12 December à 13:38, Barry Scott wrote:
>
>> I see a lot of E1101 for classes like this:
>>
>> class Foo:
>> def __init__( self ):
>> self.some_object = None
>>
>> def setSome( self, obj ):
>> self.some_object = obj
>>
>> def useSome( self ):
>> self.some_object.someMethod()
>>
>>
>> pylint will complain about the call to someMethod.
>>
>
> which pylint/astng version are you using ? I don't get any E1101 With your code
> sample (the setSome method introduce an ambiguity in the inference and
> in that case pylint don't issue E1011).
>
You are right the simple example does not break, I've not duplicated the
essence
correctly from my production code. Try this:
class Foo:
def __init__( self ):
self.some_object = None
def useSome( self ):
self.some_object.someMethod()
a.py:9: [E1101, Foo.useSome] Instance of 'None' has no 'someMethod' member
In this example it shows that someMethod is check but pylint has no
knowledge
of the intended class of some_object.
In my original example no diagnostic of produced I guess because pylints
knows
that it cannot get it right.
>
>
>> Is there a way to tell pylint that self.some_object is expected to have
>> a certain type? If not is such a feature possible to implement?
>>
>> I'm thinking about annotation like:
>> self.some_object = None # pylint: variable_type=Some
>>
>> meaning that some_object is expected to be class Some.
>>
>
> this is certainly feasible at the astng level, the main difficulty being
> that comments are not in the ast and so a preparsing of the module file
> will be necessary (i think). Anyway we'll have to support this kind of
> thing at some point...
>
>
Indeed. Adding this support will make pylint significantly more useful.
You already parse the comments to process the pylint: ones. Isn't this
an extension of
that parsing?
Barry
More information about the Python-Projects
mailing list