From 88d99c763047ebac44cb3888b02844836b8ff5ea Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 25 May 2023 22:03:11 -0700 Subject: [PATCH 1/3] Document PEP 698 in Whats New --- Doc/whatsnew/3.12.rst | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 5266f5ffb93737..cd7824596fe935 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -270,7 +270,35 @@ typed dictionaries:: See :pep:`692` for more details. -(PEP written by Franek Magiera) +(Contributed by Franek Magiera in :gh:`103629`.) + +PEP 698: Override Decorator for Static Typing +--------------------------------------------- + +A new decorator :func:`typing.override` has been added to the :mod:`typing` +module. It indicates to type checkers that the method is intended to override +a method in a superclass. This allows type checkers to catch mistakes where +a method that is intended to override a base class does not in fact do so. + +Example:: + + from typing import override + + class Base: + def get_color(self) -> str: + return "blue" + + class GoodChild(Base): + @override # ok: overrides Base.get_color + def get_color(self) -> str: + return "yellow" + + class BadChild(Base): + @override # type checker error: does not override Base.get_color + def get_colour(self) -> str: + return "red" + +(Contributed by Steven Troxler in :gh:`101561`.) Other Language Changes ====================== From 0c8dfb15a96ebe766058201b62e35fb079ea4165 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 25 May 2023 22:13:27 -0700 Subject: [PATCH 2/3] Remove duplicate mention of override, add two others --- Doc/whatsnew/3.12.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index cd7824596fe935..22b798141b5739 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -734,11 +734,6 @@ tempfile typing ------ -* Add :func:`typing.override`, an override decorator telling to static type - checkers to verify that a method overrides some method or attribute of the - same name on a base class, as per :pep:`698`. (Contributed by Steven Troxler in - :gh:`101564`.) - * :func:`isinstance` checks against :func:`runtime-checkable protocols ` now use :func:`inspect.getattr_static` rather than :func:`hasattr` to lookup whether @@ -783,6 +778,13 @@ typing or more members may be slower than in Python 3.11. (Contributed by Alex Waygood in :gh:`74690` and :gh:`103193`.) +* All :data:`typing.TypedDict` and :data:`typing.NamedTuple` classes now have the + ``__orig_bases__`` attribute. (Contributed by Adrian Garcia Badaracco in + :gh:`103699`.) + +* Add ``frozen_default`` parameter to :func:`typing.dataclass_transform`. + (Contributed by Erik De Bonte in :gh:`99957`.) + sys --- From e460c59fb15a20ebc9f77a527dbe23c7db3a2474 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 26 May 2023 06:06:25 -0700 Subject: [PATCH 3/3] Update Doc/whatsnew/3.12.rst Co-authored-by: Alex Waygood --- Doc/whatsnew/3.12.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 22b798141b5739..d6a2ff226d6b09 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -278,7 +278,8 @@ PEP 698: Override Decorator for Static Typing A new decorator :func:`typing.override` has been added to the :mod:`typing` module. It indicates to type checkers that the method is intended to override a method in a superclass. This allows type checkers to catch mistakes where -a method that is intended to override a base class does not in fact do so. +a method that is intended to override something in a base class +does not in fact do so. Example::