Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 593 Annotated containing string literal is marked incorrect #9868

Closed
Richardk2n opened this issue Dec 31, 2020 · 1 comment · Fixed by #10777
Closed

PEP 593 Annotated containing string literal is marked incorrect #9868

Richardk2n opened this issue Dec 31, 2020 · 1 comment · Fixed by #10777
Labels
bug mypy got something wrong

Comments

@Richardk2n
Copy link

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 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
@Richardk2n Richardk2n added the bug mypy got something wrong label Dec 31, 2020
@gvanrossum
Copy link
Member

Confirmed on master branch -- the last example gives Name 'metadata' is not defined.

JelleZijlstra pushed a commit that referenced this issue Nov 26, 2021
…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>
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
…d arg causing 'Name "x" is not defined" error (python#10777)

Fixes python#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
2 participants