Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion stdlib/@tests/test_cases/check_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,21 @@ def foo(self) -> None:
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)
Expand Down
18 changes: 9 additions & 9 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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.
Expand All @@ -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, ...]
Expand Down
4 changes: 2 additions & 2 deletions stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down