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 2 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
68 changes: 40 additions & 28 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
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

#
# Types and members
Expand Down Expand Up @@ -48,30 +37,53 @@ def getmembers(object: object, predicate: Optional[Callable[[Any], bool]] = ...)
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: ...
_T = TypeVar("_T")

def isclass(object: Union[Type[_T], object]) -> TypeGuard[Type[_T]]: ...
Zomatree marked this conversation as resolved.
Show resolved Hide resolved
def ismethod(object: object) -> TypeGuard[MethodType]: ...
def isfunction(object: object) -> TypeGuard[FunctionType]: ...

P = ParamSpec("P")
Zomatree marked this conversation as resolved.
Show resolved Hide resolved
_SendType = TypeVar("_SendType")
_YieldType = TypeVar("_YieldType")

if sys.version_info >= (3, 8):
def isgeneratorfunction(obj: object) -> bool: ...
def iscoroutinefunction(obj: object) -> bool: ...
def isgeneratorfunction(
obj: Union[Callable[P, Coroutine[_SendType, _YieldType, _T]], object]
) -> TypeGuard[Callable[P, Coroutine[_SendType, _YieldType, _T]]]: ...
def iscoroutinefunction(
obj: Union[Callable[P, Generator[_SendType, _YieldType, _T]], object]
) -> TypeGuard[Callable[P, Generator[_SendType, _YieldType, _T]]]: ...

else:
def isgeneratorfunction(object: object) -> bool: ...
def iscoroutinefunction(object: object) -> bool: ...

def isgenerator(object: object) -> TypeGuard[GeneratorType[Any, Any, Any]]: ...
def iscoroutine(object: object) -> TypeGuard[CoroutineType]: ...
def isawaitable(object: object) -> TypeGuard[Awaitable[Any]]: ...
def isgeneratorfunction(
object: Union[Callable[P, Coroutine[_SendType, _YieldType, _T]], object]
) -> TypeGuard[Callable[P, Generator[_SendType, _YieldType, _T]]]: ...
def iscoroutinefunction(
object: Union[Callable[P, Generator[_SendType, _YieldType, _T]], object]
) -> TypeGuard[Callable[P, Generator[_SendType, _YieldType, _T]]]: ...

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

if sys.version_info >= (3, 8):
def isasyncgenfunction(obj: object) -> bool: ...
def isasyncgenfunction(
obj: Union[Callable[P, AsyncGenerator[_YieldType, _SendType]], object]
) -> TypeGuard[Callable[P, AsyncGenerator[_YieldType, _SendType]]]: ...

else:
def isasyncgenfunction(object: object) -> bool: ...
def isasyncgenfunction(
object: Union[Callable[P, AsyncGenerator[_YieldType, _SendType]], object]
) -> TypeGuard[Callable[P, AsyncGenerator[_YieldType, _SendType]]]: ...

def isasyncgen(object: object) -> TypeGuard[AsyncGeneratorType[Any, Any]]: ...
def isasyncgen(
object: Union[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