typeddicts_required
error
Required / NotRequired used in an invalid context
PEP 655 and the typing spec restrict RequiredT and NotRequiredT to:
- Annotations of TypedDict fields
Using them outside of a TypedDict body (in regular classes, function parameters, variable annotations, etc.) is an error.
Additionally, nesting Required or NotRequired inside each other is forbidden even within a TypedDict.
class NotTypedDict:
x: Required[int] # E0035 — not a TypedDict
def func(x: NotRequired[int]) -> None: # E0035 — not a TypedDict field
...
class TD(TypedDict):
a: Required[Required[int]] # E0035 — nested Required
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
typeddicts_required down per-file or per-path from your editor or
pyproject.toml, or fix the code
so it type-checks. See the Type System rules and
the complete diagnostic reference.
Canonical URL: https://www.basilisk-python.dev/errors/typeddicts_required