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
Hey @JukkaL
I looked into it and found out that,
that is not because of the nested function. it is because probably mypy doesn't run the line giving an error. For example if you run below code with mypy,
x = 'x'
reveal_type(x)
x = 0
reveal_type(x)
it will give output:
rev.py:2: note: Revealed type is 'builtins.str'
rev.py:3: error: Incompatible types in assignment (expression has type "int", variable has type "str")
rev.py:4: note: Revealed type is 'builtins.str'
Found 1 error in 1 file (checked 1 source file)
So basically either " x = 0" line has not run or the type of x has not changed because it gave the incompatible type in assignment error.
When using --allow-redefinition the second reveal_type actually shows builtins.int. This issue is about --allow-redefinition (see the first line of the original code fragment).
I've just ran into an issue that's pretty similar to this one, even tho I do not use the allow-redefinition flag.
Here's the minimal code:
deffunc():
x: Optional[str] ="xyz"ifnotx:
returnreveal_type(x) # Revealed type is 'builtins.str'deffunc2():
reveal_type(x) # Revealed type is 'Union[builtins.str, None]'pass
It looks like the second function definition completely ignores the if not x: check, falling back to the originally defined type.
Using Python 3.8.1 and latest master branch, flags used are default VSCode ones + untyped defs:
The revealed type in this example is
int
, even though it should bestr
:The text was updated successfully, but these errors were encountered: