當在特定的代碼段上運行pylint時,如果變量已被添加到帶有.append()或+ = [var]的列表中,我會爲缺失的函數得到錯誤的否定結果。有沒有辦法避免讓pylint在這裏失去變量類型? (pylint的0.27.0,蟒蛇2.7.2)爲什麼pylint沒有在列表中檢測到缺少成員函數(E1103)?
#!/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
謝謝;我沒有區分定義和訪問,這似乎是這種情況下的關鍵。 – 2013-03-22 16:09:17