From ec3d7814d53474fe1b0642b4adb79b18af5945e8 Mon Sep 17 00:00:00 2001 From: InSync Date: Sun, 1 Dec 2024 06:10:38 +0000 Subject: [PATCH 1/4] Forbid `ClassVar` and `Final` within `TypedDict` body --- docs/spec/typeddict.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/spec/typeddict.rst b/docs/spec/typeddict.rst index 15d9aeaa..4cb064c4 100644 --- a/docs/spec/typeddict.rst +++ b/docs/spec/typeddict.rst @@ -508,6 +508,13 @@ make type declarations self-contained, and to simplify the implementation of type checkers. +ClassVar and Final items +^^^^^^^^^^^^^^^^^^^^^^^^ + +``ClassVar`` and ``Final`` are not allowed as qualifiers for an item +of a ``TypedDict``. Such an item also causes a hard error at runtime. + + Backwards Compatibility ^^^^^^^^^^^^^^^^^^^^^^^ From e9d2aeec0c56fc1aa1632256d66e6bbe1fd181da Mon Sep 17 00:00:00 2001 From: InSync Date: Sun, 1 Dec 2024 06:50:03 +0000 Subject: [PATCH 2/4] Per review --- docs/spec/class-compat.rst | 4 ++++ docs/spec/qualifiers.rst | 4 ++++ docs/spec/typeddict.rst | 7 ------- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/spec/class-compat.rst b/docs/spec/class-compat.rst index 9f88d564..e5414d38 100644 --- a/docs/spec/class-compat.rst +++ b/docs/spec/class-compat.rst @@ -89,6 +89,10 @@ annotated in ``__init__`` or other methods, rather than in the class:: def __init__(self, content): self.content: T = content +``ClassVar`` cannot be used as a qualifier for a :ref:`TypedDict ` +item or a :ref:`NamedTuple `field. Such usages are also hard +errors at runtime. + .. _`override`: ``@override`` diff --git a/docs/spec/qualifiers.rst b/docs/spec/qualifiers.rst index 4a3bcc9f..a55062ab 100644 --- a/docs/spec/qualifiers.rst +++ b/docs/spec/qualifiers.rst @@ -203,6 +203,10 @@ following should be allowed:: Y: Final = "y" N = NamedTuple("N", [(X, int), (Y, int)]) +``Final`` cannot be used as a qualifier for a :ref:`TypedDict ` +item or a :ref:`NamedTuple `field. Such usages are also hard +errors at runtime. + .. _`annotated`: ``Annotated`` diff --git a/docs/spec/typeddict.rst b/docs/spec/typeddict.rst index 4cb064c4..15d9aeaa 100644 --- a/docs/spec/typeddict.rst +++ b/docs/spec/typeddict.rst @@ -508,13 +508,6 @@ make type declarations self-contained, and to simplify the implementation of type checkers. -ClassVar and Final items -^^^^^^^^^^^^^^^^^^^^^^^^ - -``ClassVar`` and ``Final`` are not allowed as qualifiers for an item -of a ``TypedDict``. Such an item also causes a hard error at runtime. - - Backwards Compatibility ^^^^^^^^^^^^^^^^^^^^^^^ From 6bb9cfa4a94397ef30d08b449a749d0b938e208d Mon Sep 17 00:00:00 2001 From: InSync Date: Sun, 1 Dec 2024 06:53:27 +0000 Subject: [PATCH 3/4] Typo --- docs/spec/class-compat.rst | 2 +- docs/spec/qualifiers.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/spec/class-compat.rst b/docs/spec/class-compat.rst index e5414d38..c9387ba8 100644 --- a/docs/spec/class-compat.rst +++ b/docs/spec/class-compat.rst @@ -90,7 +90,7 @@ annotated in ``__init__`` or other methods, rather than in the class:: self.content: T = content ``ClassVar`` cannot be used as a qualifier for a :ref:`TypedDict ` -item or a :ref:`NamedTuple `field. Such usages are also hard +item or a :ref:`NamedTuple ` field. Such usages are also hard errors at runtime. .. _`override`: diff --git a/docs/spec/qualifiers.rst b/docs/spec/qualifiers.rst index a55062ab..5d475c44 100644 --- a/docs/spec/qualifiers.rst +++ b/docs/spec/qualifiers.rst @@ -204,7 +204,7 @@ following should be allowed:: N = NamedTuple("N", [(X, int), (Y, int)]) ``Final`` cannot be used as a qualifier for a :ref:`TypedDict ` -item or a :ref:`NamedTuple `field. Such usages are also hard +item or a :ref:`NamedTuple ` field. Such usages are also hard errors at runtime. .. _`annotated`: From 1c1fcf6874f28aaeef6417447c51d631f1e26bdb Mon Sep 17 00:00:00 2001 From: InSync Date: Sun, 1 Dec 2024 21:09:26 +0700 Subject: [PATCH 4/4] Per review --- docs/spec/class-compat.rst | 4 ++-- docs/spec/qualifiers.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/spec/class-compat.rst b/docs/spec/class-compat.rst index c9387ba8..f3086e75 100644 --- a/docs/spec/class-compat.rst +++ b/docs/spec/class-compat.rst @@ -90,8 +90,8 @@ annotated in ``__init__`` or other methods, rather than in the class:: self.content: T = content ``ClassVar`` cannot be used as a qualifier for a :ref:`TypedDict ` -item or a :ref:`NamedTuple ` field. Such usages are also hard -errors at runtime. +item or a :ref:`NamedTuple ` field. Such usage also generates +an error at runtime. .. _`override`: diff --git a/docs/spec/qualifiers.rst b/docs/spec/qualifiers.rst index 5d475c44..7ba4d9f4 100644 --- a/docs/spec/qualifiers.rst +++ b/docs/spec/qualifiers.rst @@ -204,8 +204,8 @@ following should be allowed:: N = NamedTuple("N", [(X, int), (Y, int)]) ``Final`` cannot be used as a qualifier for a :ref:`TypedDict ` -item or a :ref:`NamedTuple ` field. Such usages are also hard -errors at runtime. +item or a :ref:`NamedTuple ` field. Such usage also generates +an error at runtime. .. _`annotated`: