Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update inspect.pyi to use typevars with generics #5658

Closed
wants to merge 6 commits into from
Closed
Changes from 3 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
60 changes: 32 additions & 28 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import enum
import sys
from collections import OrderedDict
from collections.abc import Awaitable, Callable, Generator, Mapping, Sequence, Set
from types import (
AsyncGeneratorType,
BuiltinFunctionType,
CodeType,
CoroutineType,
FrameType,
FunctionType,
GeneratorType,
MethodType,
ModuleType,
TracebackType,
)
from typing import Any, ClassVar, NamedTuple, Optional, Tuple, Type, Union
from typing_extensions import Literal, TypeGuard
from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Generator, Mapping, Sequence, Set
from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
from typing import Any, ClassVar, NamedTuple, Optional, Tuple, Type, TypeVar, Union
from typing_extensions import Literal, ParamSpec, TypeGuard

_T = TypeVar("_T")
_P = ParamSpec("_P")
_SendType = TypeVar("_SendType")
_YieldType = TypeVar("_YieldType")

#
# Types and members
Expand Down Expand Up @@ -47,31 +41,41 @@ TPFLAGS_IS_ABSTRACT: int
def getmembers(object: object, predicate: Optional[Callable[[Any], bool]] = ...) -> list[Tuple[str, Any]]: ...
def getmodulename(path: str) -> Optional[str]: ...
def ismodule(object: object) -> TypeGuard[ModuleType]: ...

# TODO: use TypeGuard[Type[Any]] after python/mypy#10486 is resolved
def isclass(object: object) -> bool: ...
def isclass(object: Type[_T] | object) -> TypeGuard[Type[_T]]: ...
def ismethod(object: object) -> TypeGuard[MethodType]: ...
def isfunction(object: object) -> TypeGuard[FunctionType]: ...

if sys.version_info >= (3, 8):
def isgeneratorfunction(obj: object) -> bool: ...
def iscoroutinefunction(obj: object) -> bool: ...
def isgeneratorfunction(
obj: Callable[_P, Coroutine[_SendType, _YieldType, _T]] | object
) -> TypeGuard[Callable[_P, Coroutine[_SendType, _YieldType, _T]]]: ... # type: ignore
Zomatree marked this conversation as resolved.
Show resolved Hide resolved
def iscoroutinefunction(
obj: Callable[_P, Generator[_SendType, _YieldType, _T]] | object
) -> TypeGuard[Callable[_P, Generator[_SendType, _YieldType, _T]]]: ... # type: ignore

else:
def isgeneratorfunction(object: object) -> bool: ...
def iscoroutinefunction(object: object) -> bool: ...
def isgeneratorfunction(
object: Callable[_P, Coroutine[_SendType, _YieldType, _T]] | object
) -> TypeGuard[Callable[_P, Generator[_SendType, _YieldType, _T]]]: ... # type: ignore
def iscoroutinefunction(
object: Callable[_P, Generator[_SendType, _YieldType, _T]] | object
) -> TypeGuard[Callable[_P, Generator[_SendType, _YieldType, _T]]]: ... # type: ignore

def isgenerator(object: object) -> TypeGuard[GeneratorType[Any, Any, Any]]: ...
def iscoroutine(object: object) -> TypeGuard[CoroutineType]: ...
def isawaitable(object: object) -> TypeGuard[Awaitable[Any]]: ...
def isgenerator(object: Generator[_SendType, _YieldType, _T] | object) -> TypeGuard[Generator[_SendType, _YieldType, _T]]: ...
def iscoroutine(object: Generator[_SendType, _YieldType, _T] | object) -> TypeGuard[Generator[_SendType, _YieldType, _T]]: ...
def isawaitable(object: Awaitable[_T] | object) -> TypeGuard[Awaitable[_T]]: ...

if sys.version_info >= (3, 8):
def isasyncgenfunction(obj: object) -> bool: ...
def isasyncgenfunction(
obj: Callable[_P, AsyncGenerator[_YieldType, _SendType]] | object
) -> TypeGuard[Callable[_P, AsyncGenerator[_YieldType, _SendType]]]: ... # type: ignore

else:
def isasyncgenfunction(object: object) -> bool: ...
def isasyncgenfunction(
object: Callable[_P, AsyncGenerator[_YieldType, _SendType]] | object
) -> TypeGuard[Callable[_P, AsyncGenerator[_YieldType, _SendType]]]: ... # type: ignore

def isasyncgen(object: object) -> TypeGuard[AsyncGeneratorType[Any, Any]]: ...
def isasyncgen(object: AsyncGenerator[_YieldType, _SendType] | object) -> TypeGuard[AsyncGenerator[_YieldType, _SendType]]: ...
def istraceback(object: object) -> TypeGuard[TracebackType]: ...
def isframe(object: object) -> TypeGuard[FrameType]: ...
def iscode(object: object) -> TypeGuard[CodeType]: ...
Expand Down