diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 80584667b..108aeba94 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -160,8 +160,8 @@ class type(object): @classmethod def __prepare__(metacls, __name: str, __bases: Tuple[type, ...], **kwds: Any) -> Mapping[str, Any]: ... if sys.version_info >= (3, 10): - def __or__(self, t: Any) -> types.Union: ... - def __ror__(self, t: Any) -> types.Union: ... + def __or__(self, t: Any) -> types.UnionType: ... + def __ror__(self, t: Any) -> types.UnionType: ... class super(object): @overload @@ -1060,10 +1060,10 @@ def iter(__function: Callable[[], _T], __sentinel: Any) -> Iterator[_T]: ... if sys.version_info >= (3, 10): def isinstance( - __obj: object, __class_or_tuple: Union[type, types.Union, Tuple[Union[type, types.Union, Tuple[Any, ...]], ...]] + __obj: object, __class_or_tuple: Union[type, types.UnionType, Tuple[Union[type, types.UnionType, Tuple[Any, ...]], ...]] ) -> bool: ... def issubclass( - __cls: type, __class_or_tuple: Union[type, types.Union, Tuple[Union[type, types.Union, Tuple[Any, ...]], ...]] + __cls: type, __class_or_tuple: Union[type, types.UnionType, Tuple[Union[type, types.UnionType, Tuple[Any, ...]], ...]] ) -> bool: ... else: diff --git a/stdlib/types.pyi b/stdlib/types.pyi index a1403fea6..f55abd220 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -35,9 +35,12 @@ _KT = TypeVar("_KT") _VT_co = TypeVar("_VT_co", covariant=True) _V_co = TypeVar("_V_co", covariant=True) +@final class _Cell: + __hash__: None # type: ignore cell_contents: Any +@final class FunctionType: __closure__: Tuple[_Cell, ...] | None __code__: CodeType @@ -61,6 +64,7 @@ class FunctionType: LambdaType = FunctionType +@final class CodeType: """Create a code object. Not for the faint of heart.""" @@ -142,6 +146,7 @@ class CodeType: co_lnotab: bytes = ..., ) -> CodeType: ... +@final class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]): __hash__: None # type: ignore def __init__(self, mapping: Mapping[_KT, _VT_co]) -> None: ... @@ -159,6 +164,7 @@ class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]): def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT_co | _T2]: ... class SimpleNamespace: + __hash__: None # type: ignore def __init__(self, **kwargs: Any) -> None: ... def __getattribute__(self, name: str) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... @@ -173,6 +179,7 @@ class ModuleType: __spec__: Optional[ModuleSpec] def __init__(self, name: str, doc: Optional[str] = ...) -> None: ... +@final class GeneratorType(Generator[_T_co, _T_contra, _V_co]): gi_code: CodeType gi_frame: FrameType @@ -189,6 +196,7 @@ class GeneratorType(Generator[_T_co, _T_contra, _V_co]): @overload def throw(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> _T_co: ... +@final class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]): ag_await: Optional[Awaitable[Any]] ag_frame: FrameType @@ -205,6 +213,7 @@ class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]): def athrow(self, __typ: BaseException, __val: None = ..., __tb: Optional[TracebackType] = ...) -> Awaitable[_T_co]: ... def aclose(self) -> Awaitable[None]: ... +@final class CoroutineType: cr_await: Optional[Any] cr_code: CodeType @@ -235,6 +244,7 @@ class _StaticFunctionType: def __get__(self, obj: Optional[object], type: Optional[type]) -> FunctionType: ... +@final class MethodType: __closure__: Optional[Tuple[_Cell, ...]] # inherited from the added function __defaults__: Optional[Tuple[Any, ...]] # inherited from the added function @@ -245,6 +255,7 @@ class MethodType: def __init__(self, func: Callable[..., Any], obj: object) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... +@final class BuiltinFunctionType: __self__: typing.Union[object, ModuleType] __name__: str @@ -254,12 +265,14 @@ class BuiltinFunctionType: BuiltinMethodType = BuiltinFunctionType if sys.version_info >= (3, 7): + @final class WrapperDescriptorType: __name__: str __qualname__: str __objclass__: type def __call__(self, *args: Any, **kwargs: Any) -> Any: ... def __get__(self, obj: Any, type: type = ...) -> Any: ... + @final class MethodWrapperType: __self__: object __name__: str @@ -268,12 +281,14 @@ if sys.version_info >= (3, 7): def __call__(self, *args: Any, **kwargs: Any) -> Any: ... def __eq__(self, other: Any) -> bool: ... def __ne__(self, other: Any) -> bool: ... + @final class MethodDescriptorType: __name__: str __qualname__: str __objclass__: type def __call__(self, *args: Any, **kwargs: Any) -> Any: ... def __get__(self, obj: Any, type: type = ...) -> Any: ... + @final class ClassMethodDescriptorType: __name__: str __qualname__: str @@ -281,6 +296,7 @@ if sys.version_info >= (3, 7): def __call__(self, *args: Any, **kwargs: Any) -> Any: ... def __get__(self, obj: Any, type: type = ...) -> Any: ... +@final class TracebackType: if sys.version_info >= (3, 7): def __init__(self, tb_next: Optional[TracebackType], tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ... @@ -296,6 +312,7 @@ class TracebackType: @property def tb_lineno(self) -> int: ... +@final class FrameType: f_back: Optional[FrameType] f_builtins: Dict[str, Any] @@ -310,6 +327,7 @@ class FrameType: f_trace_opcodes: bool def clear(self) -> None: ... +@final class GetSetDescriptorType: __name__: str __objclass__: type @@ -317,6 +335,7 @@ class GetSetDescriptorType: def __set__(self, __instance: Any, __value: Any) -> None: ... def __delete__(self, obj: Any) -> None: ... +@final class MemberDescriptorType: __name__: str __objclass__: type @@ -350,6 +369,9 @@ DynamicClassAttribute = property def coroutine(func: Callable[..., Any]) -> CoroutineType: ... +if sys.version_info >= (3, 8): + CellType = _Cell + if sys.version_info >= (3, 9): class GenericAlias: __origin__: type @@ -366,7 +388,8 @@ if sys.version_info >= (3, 10): from builtins import _NotImplementedType NotImplementedType = _NotImplementedType # noqa F811 from builtins - class Union: + @final + class UnionType: __args__: Tuple[Any, ...] - def __or__(self, obj: Any) -> Union: ... - def __ror__(self, obj: Any) -> Union: ... + def __or__(self, obj: Any) -> UnionType: ... + def __ror__(self, obj: Any) -> UnionType: ... diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index e7f1884e7..41f85a315 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -171,6 +171,7 @@ ssl.SSLContext.__new__ ssl._create_unverified_context ssl.get_server_certificate tempfile.TemporaryDirectory.__init__ +types.UnionType # Renamed from `types.Union` unicodedata.ucnhash_CAPI unittest.mock.create_autospec zipfile.Path.open