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

quoted-annotation (UP037), undefined-name (F821) & quoted-type-alias (TC008) - false positives on pyright inlined TypedDicts #10812

Closed
DetachHead opened this issue Apr 7, 2024 · 3 comments · Fixed by #15073
Labels
bug Something isn't working linter Related to the linter

Comments

@DetachHead
Copy link

DetachHead commented Apr 7, 2024

pyright supports defining a TypedDict inline like so:

from __future__ import annotations
from typing import TypedDict

foo: TypedDict[{"bar": str}] = {"bar": "bar"} # errors: F821, UP037

removing the quotes causes the following pyright error:

foo: TypedDict[{bar: str}] = {"bar": "bar"} # error: Expected string literal for dictionary entry name

playground

@AlexWaygood AlexWaygood added bug Something isn't working linter Related to the linter labels Apr 7, 2024
@DetachHead DetachHead changed the title quoted-annotation (UP037) - false positive on pyright inlined TypedDicts quoted-annotation (UP037) & undefined-name (F821) - false positives on pyright inlined TypedDicts Apr 7, 2024
@AlexWaygood
Copy link
Member

Thanks, I agree that ruff's behaviour is incorrect here.

For other readers who may not be familiar — this is an experimental syntax for "inline TypedDicts" that has been floated on the (now-defunct) typing-sig mailing list. Pyright has added support for this experimental syntax so that people can experiment with it. Some more details here: python/typing#1391.

I don't believe a PEP has yet been written to formally propose this new way of writing TypedDicts. But without this new syntax, it wouldn't be a valid PEP-484 type annotation anyway, so regardless I think ruff probably shouldn't be telling people to remove the quotes in that type annotation.

@DetachHead
Copy link
Author

fyi there's now a draft PEP for this: python/peps#4082

@DetachHead
Copy link
Author

also happens with the new quoted-type-alias (TC008) rule in 0.8.1:

from typing import TypedDict

type Foo = TypedDict[{"Bar": str}] # error: Remove quotes from type alias

@DetachHead DetachHead changed the title quoted-annotation (UP037) & undefined-name (F821) - false positives on pyright inlined TypedDicts quoted-annotation (UP037), undefined-name (F821) & quoted-type-alias (TC008) - false positives on pyright inlined TypedDict`s Dec 4, 2024
@DetachHead DetachHead changed the title quoted-annotation (UP037), undefined-name (F821) & quoted-type-alias (TC008) - false positives on pyright inlined TypedDict`s quoted-annotation (UP037), undefined-name (F821) & quoted-type-alias (TC008) - false positives on pyright inlined TypedDicts Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linter Related to the linter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants