ruff icon indicating copy to clipboard operation
ruff copied to clipboard

`quoted-annotation` (`UP037`) & `undefined-name` (`F821`) - false positives on pyright inlined `TypedDict`s

Open DetachHead opened this issue 1 year ago • 1 comments

pyright supports defining a TypedDict inline like so:

from __future__ import annotations

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

removing the quotes causes the following pyright error:

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

playground

DetachHead avatar Apr 07 '24 12:04 DetachHead

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: https://github.com/python/typing/discussions/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.

AlexWaygood avatar Apr 07 '24 12:04 AlexWaygood