From 6dc254f97cd88239bbdb299f5ee040c85d0481a4 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 24 May 2023 09:34:46 -0700 Subject: [PATCH 1/4] Document NewType.__supertype__ --- Doc/library/typing.rst | 8 ++++++++ .../2023-05-24-09-34-23.gh-issue-104874.oqyJSy.rst | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-05-24-09-34-23.gh-issue-104874.oqyJSy.rst diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 92943c46ef5132..c7730ecf4c4de6 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1648,6 +1648,14 @@ These are not used in annotations. They are building blocks for declaring types. UserId = NewType('UserId', int) first_user = UserId(1) + .. attribute:: __name__ + + The name of the new type. + + .. attribute:: __supertype__ + + The type that the new type is based on. + .. versionadded:: 3.5.2 .. versionchanged:: 3.10 diff --git a/Misc/NEWS.d/next/Library/2023-05-24-09-34-23.gh-issue-104874.oqyJSy.rst b/Misc/NEWS.d/next/Library/2023-05-24-09-34-23.gh-issue-104874.oqyJSy.rst new file mode 100644 index 00000000000000..9d5904bc146421 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-24-09-34-23.gh-issue-104874.oqyJSy.rst @@ -0,0 +1,2 @@ +Document the ``__name__`` and ``__supertype__`` attributes of +:class:`typing.NewType`. Patch by Jelle Zijlstra. From 6744bffb64b2271538deb000581eb24deea04f86 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 24 May 2023 13:13:53 -0700 Subject: [PATCH 2/4] Add __module__ --- Doc/library/typing.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index c7730ecf4c4de6..164d73f6dc8475 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1648,6 +1648,10 @@ These are not used in annotations. They are building blocks for declaring types. UserId = NewType('UserId', int) first_user = UserId(1) + .. attribute:: __module__ + + The module in which the new type is defined. + .. attribute:: __name__ The name of the new type. From 2535374f2e42e8fbdc2ee6ea34bdc51404659c1b Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 24 May 2023 13:15:56 -0700 Subject: [PATCH 3/4] Update Doc/library/typing.rst --- Doc/library/typing.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 164d73f6dc8475..f9053a31ca0935 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1649,7 +1649,6 @@ These are not used in annotations. They are building blocks for declaring types. first_user = UserId(1) .. attribute:: __module__ - The module in which the new type is defined. .. attribute:: __name__ From 0308cdc6fda8d119953bddac748ce0451f1bbd45 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 24 May 2023 13:16:21 -0700 Subject: [PATCH 4/4] Update Doc/library/typing.rst --- Doc/library/typing.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index f9053a31ca0935..df16c31c43f53e 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1649,6 +1649,7 @@ These are not used in annotations. They are building blocks for declaring types. first_user = UserId(1) .. attribute:: __module__ + The module in which the new type is defined. .. attribute:: __name__