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
Annotated as descirbed by PEP 593 should work according to #7021 but does not if the Annotated is annotating a function parameter and contains a string literal, that is not itself a function parameter. Se examples below.
To Reproduce
a: Annotated[str, "metadata"] is fine def f(a: Annotated[str, str("metadata")]): is also fine def f(a: Annotated[str, "metadata"]): gives Name 'metadata' is not defined
Expected Behavior
All thre examples should be valid
Actual Behavior
They are not.
Your Environment
Mypy version used:master branch as of time of writing
Mypy command-line flags:
Mypy configuration options from mypy.ini (and other config files):
Python version used:3.9.1
Operating system and version:Windows 10
The text was updated successfully, but these errors were encountered:
…d arg causing 'Name "x" is not defined" error (#10777)
Fixes#9868
When analyzing function definitions, mypy attempts to infer type variables. The code which did that also tried to look into the second type arg to `Annotated`, which, if a string literal, resulted in a lookup which may cause a 'Name "x" is not defined" error.
Co-authored-by: 97littleleaf11 <97littleleaf11@users.noreply.github.com>
Co-authored-by: Jingchen Ye <97littleleaf11@gmail.com>
…d arg causing 'Name "x" is not defined" error (python#10777)
Fixespython#9868
When analyzing function definitions, mypy attempts to infer type variables. The code which did that also tried to look into the second type arg to `Annotated`, which, if a string literal, resulted in a lookup which may cause a 'Name "x" is not defined" error.
Co-authored-by: 97littleleaf11 <97littleleaf11@users.noreply.github.com>
Co-authored-by: Jingchen Ye <97littleleaf11@gmail.com>
Bug Report
Annotated as descirbed by PEP 593 should work according to #7021 but does not if the Annotated is annotating a function parameter and contains a string literal, that is not itself a function parameter. Se examples below.
To Reproduce
a: Annotated[str, "metadata"]
is finedef f(a: Annotated[str, str("metadata")]):
is also finedef f(a: Annotated[str, "metadata"]):
givesName 'metadata' is not defined
Expected Behavior
All thre examples should be valid
Actual Behavior
They are not.
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: