Move NotImplementedType to types.pyi (#14966)

This commit is contained in:
Randolf Scholz
2025-11-02 15:00:52 +01:00
committed by GitHub
parent 8aaa86f6a4
commit 7fde97036f
3 changed files with 26 additions and 12 deletions
+15 -1
View File
@@ -62,7 +62,21 @@ class DCAtest:
self._value = None
if sys.version_info > (3, 10):
# check that NotImplemented is treated as an "Any"
x: int = NotImplemented
if sys.version_info >= (3, 10):
# test NotImplementedType usage
assert_type(NotImplemented, types.NotImplementedType)
assert_type(types.NotImplementedType(), types.NotImplementedType)
# test EllipsisType usage
assert_type(Ellipsis, types.EllipsisType)
assert_type(types.EllipsisType(), types.EllipsisType)
# test NoneType usage (disabled, passes with pyright, but mypy errors
# assert_type(None, types.NoneType)
# assert_type(types.NoneType(), types.NoneType)
if sys.version_info >= (3, 11):
union_type = int | list[_T]
# ideally this would be `_SpecialForm` (Union)
+9 -9
View File
@@ -1367,13 +1367,6 @@ class property:
def __set__(self, instance: Any, value: Any, /) -> None: ...
def __delete__(self, instance: Any, /) -> None: ...
@final
@type_check_only
class _NotImplementedType(Any):
__call__: None
NotImplemented: _NotImplementedType
def abs(x: SupportsAbs[_T], /) -> _T: ...
def all(iterable: Iterable[object], /) -> bool: ...
def any(iterable: Iterable[object], /) -> bool: ...
@@ -2032,14 +2025,14 @@ def __import__(
def __build_class__(func: Callable[[], CellType | Any], name: str, /, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...
if sys.version_info >= (3, 10):
from types import EllipsisType
from types import EllipsisType, NotImplementedType
# Backwards compatibility hack for folks who relied on the ellipsis type
# existing in typeshed in Python 3.9 and earlier.
ellipsis = EllipsisType
Ellipsis: EllipsisType
NotImplemented: NotImplementedType
else:
# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
# not exposed anywhere under that name, we make it private here.
@@ -2049,6 +2042,13 @@ else:
Ellipsis: ellipsis
@final
@type_check_only
class _NotImplementedType(Any):
__call__: None
NotImplemented: _NotImplementedType
@disjoint_base
class BaseException:
args: tuple[Any, ...]
+2 -2
View File
@@ -717,9 +717,9 @@ if sys.version_info >= (3, 10):
@final
class EllipsisType: ...
from builtins import _NotImplementedType
@final
class NotImplementedType(Any): ...
NotImplementedType = _NotImplementedType
@final
class UnionType:
@property