]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41810: Reintroduce `types.EllipsisType`, `.NoneType` & `.NotImplementedType`...
authorBas van Beek <43369155+BvB93@users.noreply.github.com>
Tue, 22 Sep 2020 15:55:34 +0000 (17:55 +0200)
committerGitHub <noreply@github.com>
Tue, 22 Sep 2020 15:55:34 +0000 (08:55 -0700)
closes issue 41810

Doc/library/constants.rst
Doc/library/types.rst
Doc/whatsnew/3.10.rst
Lib/test/test_types.py
Lib/types.py
Misc/ACKS
Misc/NEWS.d/next/Library/2020-09-20-15-14-05.bpo-41810.7l8lyV.rst [new file with mode: 0644]

index f17e1a37875168fa9b4833cf52c5d49038b9e760..38dd552a0363acc02f683d42ed0de1f83d51c5d1 100644 (file)
@@ -19,19 +19,21 @@ A small number of constants live in the built-in namespace.  They are:
 
 .. data:: None
 
-   The sole value of the type ``NoneType``.  ``None`` is frequently used to
-   represent the absence of a value, as when default arguments are not passed to a
-   function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`.
+   An object frequently used to represent the absence of a value, as when
+   default arguments are not passed to a function. Assignments to ``None``
+   are illegal and raise a :exc:`SyntaxError`.
+   ``None`` is the sole instance of the :data:`NoneType` type.
 
 
 .. data:: NotImplemented
 
-   Special value which should be returned by the binary special methods
+   A special value which should be returned by the binary special methods
    (e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`,
    etc.) to indicate that the operation is not implemented with respect to
    the other type; may be returned by the in-place binary special methods
    (e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose.
    It should not be evaluated in a boolean context.
+   ``NotImplemented`` is the sole instance of the :data:`types.NotImplementedType` type.
 
    .. note::
 
@@ -59,8 +61,9 @@ A small number of constants live in the built-in namespace.  They are:
 .. index:: single: ...; ellipsis literal
 .. data:: Ellipsis
 
-   The same as the ellipsis literal "``...``".  Special value used mostly in conjunction
+   The same as the ellipsis literal "``...``". Special value used mostly in conjunction
    with extended slicing syntax for user-defined container data types.
+   ``Ellipsis`` is the sole instance of the :data:`types.EllipsisType` type.
 
 
 .. data:: __debug__
index 79acdf4499afd2f09b0f51c47ab26e76674e4e0e..25fa750f2ccacf1548ff348b56fd42dfeee5a544 100644 (file)
@@ -103,6 +103,13 @@ If you instantiate any of these types, note that signatures may vary between Pyt
 
 Standard names are defined for the following types:
 
+.. data:: NoneType
+
+   The type of :data:`None`.
+
+   .. versionadded:: 3.10
+
+
 .. data:: FunctionType
           LambdaType
 
@@ -186,6 +193,13 @@ Standard names are defined for the following types:
    .. versionadded:: 3.7
 
 
+.. data:: NotImplementedType
+
+   The type of :data:`NotImplemented`.
+
+   .. versionadded:: 3.10
+
+
 .. data:: MethodDescriptorType
 
    The type of methods of some built-in data types such as :meth:`str.join`.
@@ -236,6 +250,13 @@ Standard names are defined for the following types:
          Defaults to ``None``. Previously the attribute was optional.
 
 
+.. data:: EllipsisType
+
+   The type of :data:`Ellipsis`.
+
+   .. versionadded:: 3.10
+
+
 .. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
 
    The type of traceback objects such as found in ``sys.exc_info()[2]``.
index ce888fec1d8c9723c9f191ddc9132196d33788cb..f88281a934ca195d17efd3bbb559b0e84cf06922 100644 (file)
@@ -145,6 +145,14 @@ Add :data:`sys.orig_argv` attribute: the list of the original command line
 arguments passed to the Python executable.
 (Contributed by Victor Stinner in :issue:`23427`.)
 
+types
+-----
+
+Reintroduced the :data:`types.EllipsisType`, :data:`types.NoneType`
+and :data:`types.NotImplementedType` classes, providing a new set
+of types readily interpretable by type checkers.
+(Contributed by Bas van Beek in :issue:`41810`.)
+
 unittest
 --------
 
index f499fb9c8c51a440409174f6028de5747776e372..52a59d54f044d9fca481afbc4a94aef822aa281f 100644 (file)
@@ -713,6 +713,16 @@ class TypesTests(unittest.TestCase):
         assert repr(int | None) == "int | None"
         assert repr(int | typing.GenericAlias(list, int)) == "int | list[int]"
 
+    def test_ellipsis_type(self):
+        self.assertIsInstance(Ellipsis, types.EllipsisType)
+
+    def test_notimplemented_type(self):
+        self.assertIsInstance(NotImplemented, types.NotImplementedType)
+
+    def test_none_type(self):
+        self.assertIsInstance(None, types.NoneType)
+
+
 class MappingProxyTests(unittest.TestCase):
     mappingproxy = types.MappingProxyType
 
index 9642e7212caac64677b9f2a6ebcf658e2b49a3e9..532f4806fc02264ff979a449c483c97a3c993a0a 100644 (file)
@@ -296,5 +296,8 @@ def coroutine(func):
 GenericAlias = type(list[int])
 Union = type(int | str)
 
+EllipsisType = type(Ellipsis)
+NoneType = type(None)
+NotImplementedType = type(NotImplemented)
 
 __all__ = [n for n in globals() if n[:1] != '_']
index e4bd3da6b6c40abf2f6509011ab8fa8160c44ae8..7b743464c1c1c81a3cce68a69b13cc9eb8cc1c64 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -134,6 +134,7 @@ Robin Becker
 Torsten Becker
 Bill Bedford
 MichaƂ Bednarski
+Bas van Beek
 Ian Beer
 Stefan Behnel
 Reimer Behrends
diff --git a/Misc/NEWS.d/next/Library/2020-09-20-15-14-05.bpo-41810.7l8lyV.rst b/Misc/NEWS.d/next/Library/2020-09-20-15-14-05.bpo-41810.7l8lyV.rst
new file mode 100644 (file)
index 0000000..515aea9
--- /dev/null
@@ -0,0 +1,3 @@
+:data:`types.EllipsisType`, :data:`types.NotImplementedType` and
+:data:`types.NoneType` have been reintroduced, providing a new set
+of types readily interpretable by static type checkers.