Skip to content

Commit 595ffdd

Browse files
Document PEP 698 and other new typing features in What's New (#104957)
1 parent 88d14da commit 595ffdd

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

Doc/whatsnew/3.12.rst

+37-6
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,36 @@ typed dictionaries::
272272

273273
See :pep:`692` for more details.
274274

275-
(PEP written by Franek Magiera)
275+
(Contributed by Franek Magiera in :gh:`103629`.)
276+
277+
PEP 698: Override Decorator for Static Typing
278+
---------------------------------------------
279+
280+
A new decorator :func:`typing.override` has been added to the :mod:`typing`
281+
module. It indicates to type checkers that the method is intended to override
282+
a method in a superclass. This allows type checkers to catch mistakes where
283+
a method that is intended to override something in a base class
284+
does not in fact do so.
285+
286+
Example::
287+
288+
from typing import override
289+
290+
class Base:
291+
def get_color(self) -> str:
292+
return "blue"
293+
294+
class GoodChild(Base):
295+
@override # ok: overrides Base.get_color
296+
def get_color(self) -> str:
297+
return "yellow"
298+
299+
class BadChild(Base):
300+
@override # type checker error: does not override Base.get_color
301+
def get_colour(self) -> str:
302+
return "red"
303+
304+
(Contributed by Steven Troxler in :gh:`101561`.)
276305

277306
.. _whatsnew312-pep695:
278307

@@ -772,11 +801,6 @@ tempfile
772801
typing
773802
------
774803

775-
* Add :func:`typing.override`, an override decorator telling to static type
776-
checkers to verify that a method overrides some method or attribute of the
777-
same name on a base class, as per :pep:`698`. (Contributed by Steven Troxler in
778-
:gh:`101564`.)
779-
780804
* :func:`isinstance` checks against
781805
:func:`runtime-checkable protocols <typing.runtime_checkable>` now use
782806
:func:`inspect.getattr_static` rather than :func:`hasattr` to lookup whether
@@ -821,6 +845,13 @@ typing
821845
or more members may be slower than in Python 3.11. (Contributed by Alex
822846
Waygood in :gh:`74690` and :gh:`103193`.)
823847

848+
* All :data:`typing.TypedDict` and :data:`typing.NamedTuple` classes now have the
849+
``__orig_bases__`` attribute. (Contributed by Adrian Garcia Badaracco in
850+
:gh:`103699`.)
851+
852+
* Add ``frozen_default`` parameter to :func:`typing.dataclass_transform`.
853+
(Contributed by Erik De Bonte in :gh:`99957`.)
854+
824855
sys
825856
---
826857

0 commit comments

Comments
 (0)