Pregunta

When running pylint on a particular piece of code, I get false negatives for missing functions if the variables have been added to lists with .append() or += [var]. Is there any way to avoid having pylint lose the variable type here? (pylint 0.27.0, python 2.7.2)

#!/usr/bin/python

from foo.lib.machine import Machine
lh = Machine('localhost')

lh.is_reachable()      #Pylint catches this
machines = [lh]
m2 = []
m2.append(lh)
m3 = []
m3 += [lh]
for m in machines:
    m.is_reachable()   #Pylint catches this
for m in m2:
    m.is_reachable()   #Pylint MISSES this
for m in m3:
    m.is_reachable()   #Pylint MISSES this
$ pylint -i y -E pylintcheck
No config file found, using default configuration
************* Module pylintcheck
E1101:  6,0: Instance of 'Machine' has no 'is_reachable' member
E1101: 13,4: Instance of 'Machine' has no 'is_reachable' member
¿Fue útil?

Solución 2

Ned is right. For the record, when pylint tries to know what's inside a e.g. list, it only considers statements that defines this list, not all accesses to it. That explains why in your sample case, it detects correctly what's in machines but not in m2 or m3 (considered empty).

Otros consejos

Python is dynamically typed, and analysis tools have a hard time understanding everything that might happen. Looks like you've reached the end of what pylint understands.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top