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
I think that is what's causing this issue with re-definition of such variables:
# walrus_fail_demo.py
def func() -> None:
l = [0, 1, 2]
filtered_data = [new_elem for elem in l if (new_elem := 1) is not None]
filtered_data = [new_elem for elem in l if (new_elem := 1) is not None]
(since #9062 it is also possible to use this list comprehension from outside of the function scope, it will fail the same way)
Expected behaviour: re-definition of the new_v variable is allowed by mypy and adapted to.
Observed behaviour using version: 0.790+dev.8219564d365ba29dda8c4383594d9db91f26feec:
walrus_fail_demo.py:4: error: Name 'new_v' already defined on line 3
The text was updated successfully, but these errors were encountered:
(env310) akuli@akuli-desktop:~/mypy$ cat >a.py
def func() -> None:
l = [0, 1, 2]
filtered_data = [new_elem for elem in l if (new_elem := 1) is not None]
filtered_data = [new_elem for elem in l if (new_elem := 1) is not None]
(env310) akuli@akuli-desktop:~/mypy$ python3 -m mypy a.py
Success: no issues found in 1 source file
Uh oh!
There was an error while loading. Please reload this page.
There is special handling of variables defined using a named expression from within comprehensions (See https://www.python.org/dev/peps/pep-0572/#scope-of-the-target). This has been implemented in #8053 and updated in #9062
I think that is what's causing this issue with re-definition of such variables:
(since #9062 it is also possible to use this list comprehension from outside of the function scope, it will fail the same way)
Expected behaviour: re-definition of the
new_v
variable is allowed by mypy and adapted to.Observed behaviour using version: 0.790+dev.8219564d365ba29dda8c4383594d9db91f26feec:
The text was updated successfully, but these errors were encountered: