Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conformance/results/mypy/typeddicts_required.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ conformant = "Pass"
output = """
typeddicts_required.py:12: error: Required[] can be only used in a TypedDict definition [valid-type]
typeddicts_required.py:16: error: NotRequired[] can be only used in a TypedDict definition [valid-type]
typeddicts_required.py:59: error: "Required[]" type cannot be nested [valid-type]
typeddicts_required.py:60: error: "NotRequired[]" type cannot be nested [valid-type]
typeddicts_required.py:60: error: "Required[]" type cannot be nested [valid-type]
typeddicts_required.py:61: error: "NotRequired[]" type cannot be nested [valid-type]
"""
conformance_automated = "Pass"
errors_diff = """
Expand Down
4 changes: 2 additions & 2 deletions conformance/results/pycroscope/typeddicts_required.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ errors_diff = """
output = """
./typeddicts_required.py:12:7: Unexpected Required annotation [invalid_qualifier]
./typeddicts_required.py:16:7: Unexpected NotRequired annotation [invalid_qualifier]
./typeddicts_required.py:59:16: Required[] cannot be nested [invalid_qualifier]
./typeddicts_required.py:60:7: Required[] and NotRequired[] cannot be nested [invalid_qualifier]
./typeddicts_required.py:60:16: Required[] cannot be nested [invalid_qualifier]
./typeddicts_required.py:61:7: Required[] and NotRequired[] cannot be nested [invalid_qualifier]
"""
4 changes: 2 additions & 2 deletions conformance/results/pyrefly/typeddicts_required.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ output = """
ERROR typeddicts_required.py:12:5-6: `Required` may only be used for TypedDict members [invalid-annotation]
ERROR typeddicts_required.py:16:8-19: `NotRequired` is only allowed inside a class body [invalid-annotation]
ERROR typeddicts_required.py:16:8-24: `NotRequired` is not allowed in this context [invalid-annotation]
ERROR typeddicts_required.py:59:8-31: Duplicate qualifier `Required` [invalid-annotation]
ERROR typeddicts_required.py:60:8-34: Cannot combine `Required` and `NotRequired` for a TypedDict field [invalid-annotation]
ERROR typeddicts_required.py:60:8-31: Duplicate qualifier `Required` [invalid-annotation]
ERROR typeddicts_required.py:61:8-34: Cannot combine `Required` and `NotRequired` for a TypedDict field [invalid-annotation]
"""
2 changes: 1 addition & 1 deletion conformance/results/pyright/typeddicts_required.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ conformant = "Pass"
output = """
typeddicts_required.py:12:8 - error: "Required" is not allowed in this context (reportInvalidTypeForm)
typeddicts_required.py:16:8 - error: "NotRequired" is not allowed in this context (reportInvalidTypeForm)
typeddicts_required.py:59:8 - error: "Required" is not allowed in this context (reportInvalidTypeForm)
typeddicts_required.py:60:8 - error: "Required" is not allowed in this context (reportInvalidTypeForm)
typeddicts_required.py:61:8 - error: "Required" is not allowed in this context (reportInvalidTypeForm)
"""
conformance_automated = "Pass"
errors_diff = """
Expand Down
2 changes: 1 addition & 1 deletion conformance/results/ty/typeddicts_required.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ errors_diff = """
output = """
typeddicts_required.py:12:8: error[invalid-type-form] `Required` is only allowed in TypedDict fields
typeddicts_required.py:16:8: error[invalid-type-form] Type qualifier `typing.NotRequired` is not allowed in parameter annotations
typeddicts_required.py:59:8: error[invalid-type-form] `typing.Required` cannot be nested inside `Required` or `NotRequired`
typeddicts_required.py:60:8: error[invalid-type-form] `typing.Required` cannot be nested inside `Required` or `NotRequired`
typeddicts_required.py:61:8: error[invalid-type-form] `typing.Required` cannot be nested inside `Required` or `NotRequired`
"""
4 changes: 2 additions & 2 deletions conformance/results/zuban/typeddicts_required.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ errors_diff = """
output = """
typeddicts_required.py:12: error: Required[] can be only used in a TypedDict definition [valid-type]
typeddicts_required.py:16: error: NotRequired[] can be only used in a TypedDict definition [valid-type]
typeddicts_required.py:59: error: "Required[]" type cannot be nested [misc]
typeddicts_required.py:60: error: "NotRequired[]" type cannot be nested [misc]
typeddicts_required.py:60: error: "Required[]" type cannot be nested [misc]
typeddicts_required.py:61: error: "NotRequired[]" type cannot be nested [misc]
"""
3 changes: 2 additions & 1 deletion conformance/tests/typeddicts_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ class TD5(TypedDict, total=True):


class TD6(TypedDict):
# > It is also an error to nest a qualifier within itself (e.g., ``Required[Required[T]]``).
a: Required[Required[int]] # E: Nesting not allowed
b: Required[NotRequired[int]] # E: Nesting not allowed


class TD7(TypedDict):
# > Required[] and NotRequired[] can be used with Annotated[], in any nesting order.
# > These type qualifiers may be nested arbitrarily or wrapped in ``Annotated[]``.
x: Annotated[Required[int], ""]
y: Required[Annotated[int, ""]]
z: Annotated[Required[Annotated[int, ""]], ""]
Expand Down
1 change: 1 addition & 0 deletions docs/spec/typeddict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ expression contains a :term:`type expression`, optionally qualified with one of
:term:`type qualifiers <type qualifier>` ``Required``, ``NotRequired``, or ``ReadOnly``.
These type qualifiers may be nested arbitrarily or wrapped in ``Annotated[]``. It is
an error to use both ``Required`` and ``NotRequired`` in the same item definition.
It is also an error to nest a qualifier within itself (e.g., ``Required[Required[T]]``).
An item is :term:`read-only` if and only if the ``ReadOnly`` qualifier is used.

To determine whether an item is :term:`required` or :term:`non-required`, the following
Expand Down
Loading