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

not recognize type var as type annotations #7012

Closed
morning-start opened this issue Mar 5, 2025 · 1 comment
Closed

not recognize type var as type annotations #7012

morning-start opened this issue Mar 5, 2025 · 1 comment
Assignees

Comments

@morning-start
Copy link

Environment data

  • Pylance version: 2025.2.1
  • OS and version: win10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.9

Code Snippet

Image

there is a easy way

d = {}
a = type(d)


def get_user(user_id: a):
    print(1)

but bellow is ok

a = dict


def get_user(user_id: a):
    print(1)

Repro Steps

  1. XXX

Expected behavior

XXX

Actual behavior

XXX

Logs

XXX
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Mar 5, 2025
@erictraut
Copy link
Contributor

erictraut commented Mar 5, 2025

As the error message indicates, variables are not allowed in type expressions (annotations). This is mandated by the Python typing spec. Type annotations need to be statically evaluated, so they cannot rely on dynamic runtime behaviors. For more details, refer to this chapter of the Python typing spec.

@debonte debonte added by design and removed needs repro Issue has not been reproduced yet labels Mar 5, 2025
@debonte debonte closed this as completed Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants