[Python-projects] Suggestion about E1101 Instance of 'None' has no 'get' member
Barry Scott
barry.scott at onelan.co.uk
Wed Dec 13 16:41:10 CET 2006
Sylvain Thénault wrote:
>
>>>> 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?
>>
>
> Well yes and no since ideally it should be at the astng level, so other
> astng based program take advantage of this information as well. Another
> idea would be to get information from lines such as :
>
> assert isinstance(self.attr, aclass)
>
> as Adrien suggested to me.
>
That is a nice idea, especially if you pick up the info from any method
of a class
so that it does not have to be executed at runtime of the code.
Something like:
class Foo:
def __init__( self ):
self.some_object = None
def useSome( self ):
self.some_object.someMethod()
def __pylint_hint( self ):
assert isinstance( self.some_object, some_module.SomeClass )
Barry
More information about the Python-Projects
mailing list