pytype icon indicating copy to clipboard operation
pytype copied to clipboard

False positive for disjoint type ranges

Open yugr opened this issue 5 years ago • 2 comments

Sorry if that's a known issue.

This code

def visit_goals(lst, f):
    for x in lst:
        f(x)

goals = set()
visit_goals([], lambda g: goals.add(g))

def foo():
    return [1, 2, 3]

goals = foo()
for g in goals:
    print(g)

causes pytype 2020.4.22 to emit

<lambda>: No attribute 'add' on List[int] [attribute-error]

yugr avatar May 05 '20 13:05 yugr

Oh interesting. I guess since we analyze the lambda after we finish executing the module-level code, we think goals is a list at that point.

The easiest workaround would be to use a different name for the second variable.

rchen152 avatar May 07 '20 00:05 rchen152

Yup, that would fix my particular case.

yugr avatar May 08 '20 18:05 yugr