-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
MyPy has a flag --allow-redefinition to enable variable redefinition in limited circumstances. This doesn't seem to work with variables bound in a for loop iteration.
To Reproduce
for i in range(3):
i: str = str(i)
reveal_type(i)
def test(i: int):
i: str = str(i)
reveal_type(i)Expected Behavior
Both cases are allowed.
Actual Behavior
MyPy throws an error only for line 2.
main.py:2: error: Name "i" already defined on line 1 [no-redef]
main.py:3: note: Revealed type is "builtins.int"
main.py:7: note: Revealed type is "builtins.str"
Found 1 error in 1 file (checked 1 source file)
Your Environment
MyPy Version v1.5.1
Hnasar, m-danya and Avasam
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong