You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
isinstance checks cause type declarations to leak from the binder #1568
This is obviously a bug, but it's not yet clear what the best way to fix the issue is. The binder is small, but complicated -- perhaps the best fix is it rewrite it in a more understandable/robust way?
This issue is the reason mypy still has a self-typecheck error with #1562.
I'm actually not going to fix this right now, in part because the correct behavior isn't entirely clear; should we treat comprehension loop variables as deleted after the comprehension (maybe only in Python 2 mode)?
In CPython, comprehension variables are deleted only in Python 3. But I'm
fine with mypy treating them as deleted everywhere -- even in Python 2
mode. If you reference a leaked comprehension variable your code is very
smelly. Another aspect of comprehensions is that we should not insist on
the same variable having the same type throughout a function.
Also note that generator expressions are different -- the are always their
own scope even in Python 2.
Oh right and there's also the tricky bit that while list comprehensions are evaluated immediately (of course), only the first sequence in a generator comprehension is evaluated immediately. So technically we should not use information from the binder for any sequence expression past the first. (Like we don't use information from the binder when checking the body of a lambda, since the variables it refers to may have changed value by the time the lambda is executed.)
Activity
gvanrossum commentedon May 24, 2016
ddfisher commentedon May 24, 2016
Right. But I think I'd be pretty reasonable to tell people not to use that in Python 2.
rwbarton commentedon May 31, 2016
Hi @ecprice :)
rwbarton commentedon Jun 22, 2016
#1044 looks like it might be the same issue.
ecprice commentedon Jun 22, 2016
I think the top commit of my typebinder branch fixes this. It probably cleanly applies to master, but I haven't checked.
rwbarton commentedon Jun 29, 2016
I'm actually not going to fix this right now, in part because the correct behavior isn't entirely clear; should we treat comprehension loop variables as deleted after the comprehension (maybe only in Python 2 mode)?
gvanrossum commentedon Jun 29, 2016
rwbarton commentedon Jun 29, 2016
Oh right and there's also the tricky bit that while list comprehensions are evaluated immediately (of course), only the first sequence in a generator comprehension is evaluated immediately. So technically we should not use information from the binder for any sequence expression past the first. (Like we don't use information from the binder when checking the body of a lambda, since the variables it refers to may have changed value by the time the lambda is executed.)
elazarg commentedon Apr 3, 2017
The output now is
error: Revealed type is 'builtins.list[builtins.int*]'as I assume it should be.ilevkivskyi commentedon Apr 3, 2017
I am not sure how this got fixed, but the current behaviour looks right to me.