Skip to content
Closed
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
11 changes: 4 additions & 7 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ WriteableBuffer = Union[bytearray, memoryview, array.array[Any], mmap.mmap, ctyp
ReadableBuffer = Union[ReadOnlyBuffer, WriteableBuffer] # stable

# stable
if sys.version_info >= (3, 10):
from types import NoneType as NoneType
else:
# Used by type checkers for checks involving None (does not exist at runtime)
@final
class NoneType:
def __bool__(self) -> Literal[False]: ...
# Used by type checkers for checks involving None (does not exist at runtime)
@final
class NoneType:
def __bool__(self) -> Literal[False]: ...
7 changes: 1 addition & 6 deletions stdlib/asyncio/coroutines.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import types
from collections.abc import Callable, Coroutine
from typing import Any, TypeVar
Expand All @@ -9,8 +8,4 @@ _F = TypeVar("_F", bound=Callable[..., Any])
def coroutine(func: _F) -> _F: ...
def iscoroutinefunction(func: object) -> bool: ...

if sys.version_info < (3, 8):
def iscoroutine(obj: object) -> TypeGuard[types.GeneratorType[Any, Any, Any] | Coroutine[Any, Any, Any]]: ...

else:
def iscoroutine(obj: object) -> TypeGuard[Coroutine[Any, Any, Any]]: ...
def iscoroutine(obj: object) -> TypeGuard[types.GeneratorType | Coroutine[Any, Any, Any]]: ...
29 changes: 15 additions & 14 deletions stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class _Cell:
cell_contents: Any

@final
class FunctionType:
class FunctionType(Callable):
__closure__: Tuple[_Cell, ...] | None
__code__: CodeType
__defaults__: Tuple[Any, ...] | None
Expand Down Expand Up @@ -248,7 +248,7 @@ class _StaticFunctionType:
def __get__(self, obj: object | None, type: type | None) -> FunctionType: ...

@final
class MethodType:
class MethodType(Callable):
__closure__: Tuple[_Cell, ...] | None # inherited from the added function
__defaults__: Tuple[Any, ...] | None # inherited from the added function
__func__: _StaticFunctionType
Expand All @@ -259,7 +259,7 @@ class MethodType:
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...

@final
class BuiltinFunctionType:
class BuiltinFunctionType(Callable):
__self__: object | ModuleType
__name__: str
__qualname__: str
Expand All @@ -269,14 +269,14 @@ BuiltinMethodType = BuiltinFunctionType

if sys.version_info >= (3, 7):
@final
class WrapperDescriptorType:
class WrapperDescriptorType(Callable):
__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:
class MethodWrapperType(Callable):
__self__: object
__name__: str
__qualname__: str
Expand All @@ -285,14 +285,14 @@ if sys.version_info >= (3, 7):
def __eq__(self, other: Any) -> bool: ...
def __ne__(self, other: Any) -> bool: ...
@final
class MethodDescriptorType:
class MethodDescriptorType(Callable):
__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:
class ClassMethodDescriptorType(Callable):
__name__: str
__qualname__: str
__objclass__: type
Expand Down Expand Up @@ -375,18 +375,19 @@ def coroutine(func: Callable[..., Any]) -> CoroutineType[Any, Any, Any]: ...
if sys.version_info >= (3, 8):
CellType = _Cell

_Origin = TypeVar("_Origin", bound=type)
_Args = TypeVar("_Args", bound=tuple[object, ...])

if sys.version_info >= (3, 9):
class GenericAlias:
__origin__: type
__args__: Tuple[Any, ...]
class GenericAlias(Generic[_Origin, _Args]):
__origin__: _Origin
__args__: _Args
__parameters__: Tuple[Any, ...]
def __init__(self, origin: type, args: Any) -> None: ...
def __init__(self, origin: _Origin, args: _Args) -> None: ...
def __getattr__(self, name: str) -> Any: ... # incomplete

if sys.version_info >= (3, 10):
@final
class NoneType:
def __bool__(self) -> Literal[False]: ...
NoneType = type(None)
EllipsisType = ellipsis # noqa F811 from builtins
from builtins import _NotImplementedType

Expand Down
22 changes: 19 additions & 3 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,25 @@ class TypeVar:

_promote = object()

class _SpecialForm:
def __getitem__(self, typeargs: Any) -> object: ...
_Origin = TypeVar("_Origin", bound=type)
_Args = TypeVar("_Args", bound=tuple[object, ...])

class _SpecialForm(Generic[_Origin]):
@overload
def __getitem__(self, typeargs: _Args) -> _GenericAlias[_Origin, _Args]: ...
@overload
def __getitem__(self, typeargs: _T) -> _GenericAlias[_Origin, tuple[_T]]: ...

_F = TypeVar("_F", bound=Callable[..., Any])
_P = _ParamSpec("_P")
_T = TypeVar("_T")

def overload(func: _F) -> _F: ...

class _GenericAlias(Generic[_Origin, _Args]):
__origin__: _Origin
__args__: _Args

Union: _SpecialForm = ...
Optional: _SpecialForm = ...
Tuple: _SpecialForm = ...
Expand All @@ -53,7 +63,7 @@ ClassVar: _SpecialForm = ...
if sys.version_info >= (3, 8):
Final: _SpecialForm = ...
def final(f: _T) -> _T: ...
Literal: _SpecialForm = ...
Literal: _SpecialForm[object] = ...
# TypedDict is a (non-subscriptable) special form.
TypedDict: object

Expand Down Expand Up @@ -647,7 +657,13 @@ else:
) -> dict[str, Any]: ...

if sys.version_info >= (3, 8):
@overload
def get_origin(tp: _GenericAlias[_Origin, _Args]) -> _Origin: ...
@overload
def get_origin(tp: Any) -> Any | None: ...
@overload
def get_args(tp: _GenericAlias[_Origin, _Args]) -> _Args: ...
@overload
def get_args(tp: Any) -> Tuple[Any, ...]: ...

@overload
Expand Down