Skip to content

Commit 0d0e9fe

Browse files
authoredSep 22, 2020
bpo-41810: Reintroduce types.EllipsisType, .NoneType & .NotImplementedType (GH-22336)
closes issue 41810
1 parent a68a2ad commit 0d0e9fe

File tree

7 files changed

+54
-5
lines changed

7 files changed

+54
-5
lines changed
 

‎Doc/library/constants.rst

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ A small number of constants live in the built-in namespace. They are:
1919

2020
.. data:: None
2121

22-
The sole value of the type ``NoneType``. ``None`` is frequently used to
23-
represent the absence of a value, as when default arguments are not passed to a
24-
function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`.
22+
An object frequently used to represent the absence of a value, as when
23+
default arguments are not passed to a function. Assignments to ``None``
24+
are illegal and raise a :exc:`SyntaxError`.
25+
``None`` is the sole instance of the :data:`NoneType` type.
2526

2627

2728
.. data:: NotImplemented
2829

29-
Special value which should be returned by the binary special methods
30+
A special value which should be returned by the binary special methods
3031
(e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`,
3132
etc.) to indicate that the operation is not implemented with respect to
3233
the other type; may be returned by the in-place binary special methods
3334
(e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose.
3435
It should not be evaluated in a boolean context.
36+
``NotImplemented`` is the sole instance of the :data:`types.NotImplementedType` type.
3537

3638
.. note::
3739

@@ -59,8 +61,9 @@ A small number of constants live in the built-in namespace. They are:
5961
.. index:: single: ...; ellipsis literal
6062
.. data:: Ellipsis
6163

62-
The same as the ellipsis literal "``...``". Special value used mostly in conjunction
64+
The same as the ellipsis literal "``...``". Special value used mostly in conjunction
6365
with extended slicing syntax for user-defined container data types.
66+
``Ellipsis`` is the sole instance of the :data:`types.EllipsisType` type.
6467

6568

6669
.. data:: __debug__

‎Doc/library/types.rst

+21
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ If you instantiate any of these types, note that signatures may vary between Pyt
103103

104104
Standard names are defined for the following types:
105105

106+
.. data:: NoneType
107+
108+
The type of :data:`None`.
109+
110+
.. versionadded:: 3.10
111+
112+
106113
.. data:: FunctionType
107114
LambdaType
108115

@@ -186,6 +193,13 @@ Standard names are defined for the following types:
186193
.. versionadded:: 3.7
187194

188195

196+
.. data:: NotImplementedType
197+
198+
The type of :data:`NotImplemented`.
199+
200+
.. versionadded:: 3.10
201+
202+
189203
.. data:: MethodDescriptorType
190204

191205
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:
236250
Defaults to ``None``. Previously the attribute was optional.
237251

238252

253+
.. data:: EllipsisType
254+
255+
The type of :data:`Ellipsis`.
256+
257+
.. versionadded:: 3.10
258+
259+
239260
.. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
240261

241262
The type of traceback objects such as found in ``sys.exc_info()[2]``.

‎Doc/whatsnew/3.10.rst

+8
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ Add :data:`sys.orig_argv` attribute: the list of the original command line
145145
arguments passed to the Python executable.
146146
(Contributed by Victor Stinner in :issue:`23427`.)
147147

148+
types
149+
-----
150+
151+
Reintroduced the :data:`types.EllipsisType`, :data:`types.NoneType`
152+
and :data:`types.NotImplementedType` classes, providing a new set
153+
of types readily interpretable by type checkers.
154+
(Contributed by Bas van Beek in :issue:`41810`.)
155+
148156
unittest
149157
--------
150158

‎Lib/test/test_types.py

+10
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,16 @@ def test_or_type_repr(self):
713713
assert repr(int | None) == "int | None"
714714
assert repr(int | typing.GenericAlias(list, int)) == "int | list[int]"
715715

716+
def test_ellipsis_type(self):
717+
self.assertIsInstance(Ellipsis, types.EllipsisType)
718+
719+
def test_notimplemented_type(self):
720+
self.assertIsInstance(NotImplemented, types.NotImplementedType)
721+
722+
def test_none_type(self):
723+
self.assertIsInstance(None, types.NoneType)
724+
725+
716726
class MappingProxyTests(unittest.TestCase):
717727
mappingproxy = types.MappingProxyType
718728

‎Lib/types.py

+3
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,8 @@ def wrapped(*args, **kwargs):
296296
GenericAlias = type(list[int])
297297
Union = type(int | str)
298298

299+
EllipsisType = type(Ellipsis)
300+
NoneType = type(None)
301+
NotImplementedType = type(NotImplemented)
299302

300303
__all__ = [n for n in globals() if n[:1] != '_']

‎Misc/ACKS

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Robin Becker
134134
Torsten Becker
135135
Bill Bedford
136136
Michał Bednarski
137+
Bas van Beek
137138
Ian Beer
138139
Stefan Behnel
139140
Reimer Behrends
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:data:`types.EllipsisType`, :data:`types.NotImplementedType` and
2+
:data:`types.NoneType` have been reintroduced, providing a new set
3+
of types readily interpretable by static type checkers.

0 commit comments

Comments
 (0)
Please sign in to comment.