Given lib.py:
x = 1
def f():
reveal_type(x)
def g():
global x
x = 2
x = "foo"
And main.py:
from lib import x
import lib
reveal_type(x)
reveal_type(lib.x)
lib.x = 2
lib.x = "foo"
(Multiplay gist ID e8a25e05120c2a275f26096e7a3c01d7, for those who multiplay.)
We currently reveal Literal[1] at all three reveal_type calls, and error on neither assignment to the global x in g, but on both assignments to lib.x.
I believe that the behavior here that would be most consistent with our handling of class attributes, and would match intent in the most cases, would be to reveal int on all three reveal_type calls, and error on both assignments of "foo" but neither assignment of 2.
This describes the behavior of mypy. All other type checkers currently have some deviation from this behavior, none of which make much sense to me.
Given
lib.py:And
main.py:(Multiplay gist ID e8a25e05120c2a275f26096e7a3c01d7, for those who multiplay.)
We currently reveal
Literal[1]at all threereveal_typecalls, and error on neither assignment to theglobalx ing, but on both assignments tolib.x.I believe that the behavior here that would be most consistent with our handling of class attributes, and would match intent in the most cases, would be to reveal
inton all threereveal_typecalls, and error on both assignments of"foo"but neither assignment of2.This describes the behavior of mypy. All other type checkers currently have some deviation from this behavior, none of which make much sense to me.