[Python-projects] pylint: E1101: Instance of 'None' has no 'xyz' member

Sylvain Thénault sylvain.thenault at logilab.fr
Mon Apr 14 11:43:06 CEST 2008


On Mon, Apr 14, 2008 at 11:25:55AM +0200, Duncan Gibson wrote:
> I wrote:
> > > There are various places in my code where I have something like:
> > >     thing = findThing()
> > >     if thing is not None:
> > >         thing.doIt()
> > > but pylint reports E1101: Instance of 'None' has no 'doIt' member.
> > > Apart from adding # pylint: disable-msg=E1101 comments everywhere
> > > in the code, is there some way of restructuring the code to avoid
> > > the [unnecessary?] warning?
> 
> Alexandre replied:
> > First question that comes to my mind: can the call to findThing
> > return None? If not, then do not add a test just to please pylint.
> 
> Yes, findThing() can return None, so the test is already there.
> I am very happy that pylint reports the problem when I forget to
> add the test, but it is a little inconvenient that pylint still
> reports a problem even when the test is there. This pattern occurs
> very frequently in the code, so there are always spurious warnings
> so a real problem report could easily be missed.
> 
> In the other reply, Sylvain said that no versions of pylint/astng
> currently handle this problem, but it would be a useful feature, so
> could I make this a request for future enchancement?

sure you can, I'll add this to astng tracker. Though we've very little
time for pylint those days so I can't tell when this will be
available...

-- 
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