@@ -297,6 +297,38 @@ See :pep:`675` for more details.
297297(Contributed by Jelle Zijlstra in :issue: `47088 `. PEP written by Pradeep
298298Kumar Srinivasan and Graham Bleaney.)
299299
300+ PEP 681: Data Class Transforms
301+ ------------------------------
302+
303+ The new :data: `~typing.dataclass_transform ` annotation may be used to
304+ decorate a function that is itself a decorator, a class, or a metaclass.
305+ The presence of ``@dataclass_transform() `` tells a static type checker that the
306+ decorated function, class, or metaclass performs runtime "magic" that
307+ transforms a class, endowing it with dataclass-like behaviors.
308+
309+ For example::
310+
311+ # The ``create_model`` decorator is defined by a library.
312+ @typing.dataclass_transform()
313+ def create_model(cls: Type[_T]) -> Type[_T]:
314+ cls.__init__ = ...
315+ cls.__eq__ = ...
316+ cls.__ne__ = ...
317+ return cls
318+
319+ # The ``create_model`` decorator can now be used to create new model
320+ # classes, like this:
321+ @create_model
322+ class CustomerModel:
323+ id: int
324+ name: str
325+
326+ c = CustomerModel(id=327, name="John Smith")
327+
328+ See :pep: `681 ` for more details.
329+
330+ (Contributed by Jelle Zijlstra in :gh: `91860 `. PEP written by
331+ Erik De Bonte and Eric Traut.)
300332
301333Other Language Changes
302334======================
@@ -649,6 +681,39 @@ time
649681 it had a resolution of 1 millisecond (10\ :sup: `-3` seconds).
650682 (Contributed by Benjamin Szőke, Dong-hee Na, Eryk Sun and Victor Stinner in :issue: `21302 ` and :issue: `45429 `.)
651683
684+ typing
685+ ------
686+
687+ For major changes, see :ref: `new-feat-related-type-hints-311 `.
688+
689+ * Add :func: `typing.assert_never ` and :class: `typing.Never `.
690+ :func: `typing.assert_never ` is useful for asking a type checker to confirm
691+ that a line of code is not reachable. At runtime, it raises an
692+ :exc: `AssertionError `.
693+ (Contributed by Jelle Zijlstra in :gh: `90633 `.)
694+
695+ * Add :func: `typing.reveal_type `. This is useful for asking a type checker
696+ what type it has inferred for a given expression. At runtime it prints
697+ the type of the received value.
698+ (Contributed by Jelle Zijlstra in :gh: `90572 `.)
699+
700+ * Add :func: `typing.assert_type `. This is useful for asking a type checker
701+ to confirm that the type it has inferred for a given expression matches
702+ the given type. At runtime it simply returns the received value.
703+ (Contributed by Jelle Zijlstra in :gh: `90638 `.)
704+
705+ * Allow subclassing of :class: `typing.Any `. This is useful for avoiding
706+ type checker errors related to highly dynamic class, such as mocks.
707+ (Contributed by Shantanu Jain in :gh: `91154 `.)
708+
709+ * The :func: `typing.final ` decorator now sets the ``__final__ `` attributed on
710+ the decorated object.
711+ (Contributed by Jelle Zijlstra in :gh: `90500 `.)
712+
713+ * The :func: `typing.get_overloads ` function can be used for introspecting
714+ the overloads of a function. :func: `typing.clear_overloads ` can be used
715+ to clear all registered overloads of a function.
716+ (Contributed by Jelle Zijlstra in :gh: `89263 `.)
652717
653718unicodedata
654719-----------
0 commit comments