Skip to content

Fix function containing PEP 593 Annotated with a string literal second arg causing 'Name "x" is not defined" error #10777

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

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into 9868/fix-func-with-annotated-containing-st…
…r-literal
  • Loading branch information
97littleleaf11 authored Nov 26, 2021
commit ff7618b61b28ba213cd746e369babf132b640512
16 changes: 13 additions & 3 deletions test-data/unit/check-annotated.test
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,24 @@ reveal_type(x) # N: Revealed type is "def () -> builtins.int"

[case testAnnotatedStringLiteralInFunc]
from typing_extensions import Annotated

def f1(a: Annotated[str, "metadata"]):
pass
reveal_type(f1) # N: Revealed type is "def (a: builtins.str) -> Any"

def f2(a: Annotated["str", "metadata"]):
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you reveal_type() this one too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe also add a testcase with a generic function, so we can confirm that a typevar in the first arg to Annotated is still picked up correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelleZijlstra I added a case. Is it correct?


def f3(a: Annotated["notdefined", "metadata"]): # E: Name "notdefined" is not defined
pass

[case testSliceAnnotated39]
# flags: --python-version 3.9
from typing_extensions import Annotated
a: Annotated[int, 1:2]
reveal_type(a) # N: Revealed type is "builtins.int"
[builtins fixtures/tuple.pyi]

[case testSliceAnnotated38]
# flags: --python-version 3.8
from typing_extensions import Annotated
a: Annotated[int, 1:2]
reveal_type(a) # N: Revealed type is "builtins.int"
[builtins fixtures/tuple.pyi]
You are viewing a condensed version of this merge commit. You can view the full changes here.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy