[Python-projects] Suggestion about E1101 Instance of 'None' has no 'get' member
Barry Scott
barry.scott at onelan.co.uk
Tue Dec 12 19:24:12 CET 2006
Michael Foord wrote:
> 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.
>>
>> 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.
>>
>
> Hmmm... my 2 cents worh (maybe less).
>
> It seems like a valid warning. In our code we always do :
>
> if self.some_object is not None:
> self.some_object.some_method()
This will not prevent the issuing of a E1101. Its not a warning its an
error.
pylint is unable to determine what the type that some_object may be. It
notices
the assignment in setSome but that contains no type info either.
There is a work around that I tried this afternoon.
Adding a function that is never called that does the init does give
pylint the info it needs. For example:
def __pylint( self ):
import some
self.some_object = some.SomeObject()
This only works if the import order of modules allows Foo to import some.
Barry
More information about the Python-Projects
mailing list