Closed runfalk closed 1 month ago
I don't think it's because or Required
or NotRequired
, but because of using typing.
.
For:
import typing
class Something(typing.TypedDict):
One: typing.NotRequired[str]
Two: typing.NotRequired[float]
I get error: Variable not allowed in type expression (reportInvalidTypeForm)
for One and Two. No such errors for:
import typing
from typing import NotRequired
class Something(typing.TypedDict):
One: NotRequired[str]
Two: NotRequired[float]
Apologies for the regression. This will be fixed in the next release.
This bug is specific to the fully-qualified form (typing.Required
) and doesn't appear with just Required
. Most developers use the latter form (via a from typing import Required
statement). The fully-qualified form didn't previously appear in our unit tests nor did it appear in the 120 or so public repositories that we use for regression testing. I've updated our unit tests to include this form.
There is some special-casing that's required for Required
and similar special forms because they are defined in typing.pyi
and typing_extensions.pyi
using a statement form that looks like a variable declaration (Required: _SpecialForm
).
This is addressed in pyright 1.1.372.
Describe the bug
typing.NotRequired
no longer seem to be allowed intyping.TypedDict
. The same seems to be true fortyping.Required
whentotal=False
.Code or Screenshots This is an example from the standard library docs (https://docs.python.org/3/library/typing.html#typing.TypedDict).
VS Code extension or command-line Versions:
Pyright config: