Skip to content

Commit 7fde970

Browse files
Move NotImplementedType to types.pyi (#14966)
1 parent 8aaa86f commit 7fde970

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

stdlib/@tests/test_cases/check_types.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,21 @@ def foo(self) -> None:
6262
self._value = None
6363

6464

65-
if sys.version_info > (3, 10):
65+
# check that NotImplemented is treated as an "Any"
66+
x: int = NotImplemented
67+
68+
if sys.version_info >= (3, 10):
69+
# test NotImplementedType usage
70+
assert_type(NotImplemented, types.NotImplementedType)
71+
assert_type(types.NotImplementedType(), types.NotImplementedType)
72+
# test EllipsisType usage
73+
assert_type(Ellipsis, types.EllipsisType)
74+
assert_type(types.EllipsisType(), types.EllipsisType)
75+
# test NoneType usage (disabled, passes with pyright, but mypy errors
76+
# assert_type(None, types.NoneType)
77+
# assert_type(types.NoneType(), types.NoneType)
78+
79+
if sys.version_info >= (3, 11):
6680
union_type = int | list[_T]
6781

6882
# ideally this would be `_SpecialForm` (Union)

stdlib/builtins.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,13 +1367,6 @@ class property:
13671367
def __set__(self, instance: Any, value: Any, /) -> None: ...
13681368
def __delete__(self, instance: Any, /) -> None: ...
13691369

1370-
@final
1371-
@type_check_only
1372-
class _NotImplementedType(Any):
1373-
__call__: None
1374-
1375-
NotImplemented: _NotImplementedType
1376-
13771370
def abs(x: SupportsAbs[_T], /) -> _T: ...
13781371
def all(iterable: Iterable[object], /) -> bool: ...
13791372
def any(iterable: Iterable[object], /) -> bool: ...
@@ -2032,14 +2025,14 @@ def __import__(
20322025
def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...
20332026

20342027
if sys.version_info >= (3, 10):
2035-
from types import EllipsisType
2028+
from types import EllipsisType, NotImplementedType
20362029

20372030
# Backwards compatibility hack for folks who relied on the ellipsis type
20382031
# existing in typeshed in Python 3.9 and earlier.
20392032
ellipsis = EllipsisType
20402033

20412034
Ellipsis: EllipsisType
2042-
2035+
NotImplemented: NotImplementedType
20432036
else:
20442037
# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
20452038
# not exposed anywhere under that name, we make it private here.
@@ -2049,6 +2042,13 @@ else:
20492042

20502043
Ellipsis: ellipsis
20512044

2045+
@final
2046+
@type_check_only
2047+
class _NotImplementedType(Any):
2048+
__call__: None
2049+
2050+
NotImplemented: _NotImplementedType
2051+
20522052
@disjoint_base
20532053
class BaseException:
20542054
args: tuple[Any, ...]

stdlib/types.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,9 @@ if sys.version_info >= (3, 10):
717717
@final
718718
class EllipsisType: ...
719719

720-
from builtins import _NotImplementedType
720+
@final
721+
class NotImplementedType(Any): ...
721722

722-
NotImplementedType = _NotImplementedType
723723
@final
724724
class UnionType:
725725
@property

0 commit comments

Comments
 (0)