[Python-projects] Suggestion about E1101 Instance of 'None' has no 'get' member
Sylvain Thénault
sylvain.thenault at logilab.fr
Wed Dec 13 14:29:18 CET 2006
On Wednesday 13 December à 11:51, Barry Scott wrote:
> 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
yep, as I already said before, having a setXXX method help pylint by
introducing an inference ambiguity so it'll skip related E1011.
> >> 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.
--
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
Python et calcul scientifique: http://www.logilab.fr/science
More information about the Python-Projects
mailing list