Skip to content
Open
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
23 changes: 18 additions & 5 deletions stdlib/@tests/test_cases/check_inspect.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import annotations

import inspect
from collections.abc import Awaitable, Callable, Coroutine
from types import CoroutineType
from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Generator
from typing import Any
from typing_extensions import assert_type

Expand All @@ -17,10 +16,24 @@ def test_iscoroutinefunction_inspect(
assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]])

if inspect.iscoroutinefunction(y):
assert_type(y, Callable[[str, int], CoroutineType[Any, Any, bytes]])
assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]])

if inspect.iscoroutinefunction(z):
assert_type(z, Callable[[str, int], CoroutineType[Any, Any, Any]])
assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]])

if inspect.iscoroutinefunction(xx):
assert_type(xx, Callable[..., CoroutineType[Any, Any, Any]])
assert_type(xx, Callable[..., Coroutine[Any, Any, Any]])


def test_isgeneratorfunction_inspect(x: Callable[[str], object], y: object) -> None:
if inspect.isgeneratorfunction(x):
assert_type(x, Callable[[str], Generator[Any, Any, Any]])
if inspect.isgeneratorfunction(y):
assert_type(y, Callable[..., Generator[Any, Any, Any]])


def test_isasyncgenfunction_inspect(x: Callable[[str], object], y: object) -> None:
if inspect.isasyncgenfunction(x):
assert_type(x, Callable[[str], AsyncGenerator[Any, Any]])
if inspect.isasyncgenfunction(y):
assert_type(y, Callable[..., AsyncGenerator[Any, Any]])
14 changes: 7 additions & 7 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,18 @@ if sys.version_info >= (3, 12):
@overload
def isgeneratorfunction(obj: Callable[..., Generator[Any, Any, Any]]) -> bool: ...
@overload
def isgeneratorfunction(obj: Callable[_P, Any]) -> TypeGuard[Callable[_P, GeneratorType[Any, Any, Any]]]: ...
def isgeneratorfunction(obj: Callable[_P, Any]) -> TypeGuard[Callable[_P, Generator[Any, Any, Any]]]: ...
@overload
def isgeneratorfunction(obj: object) -> TypeGuard[Callable[..., GeneratorType[Any, Any, Any]]]: ...
def isgeneratorfunction(obj: object) -> TypeGuard[Callable[..., Generator[Any, Any, Any]]]: ...

@overload
def iscoroutinefunction(obj: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
@overload
def iscoroutinefunction(obj: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, CoroutineType[Any, Any, _T]]]: ...
def iscoroutinefunction(obj: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
@overload
def iscoroutinefunction(obj: Callable[_P, object]) -> TypeGuard[Callable[_P, CoroutineType[Any, Any, Any]]]: ...
def iscoroutinefunction(obj: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
@overload
def iscoroutinefunction(obj: object) -> TypeGuard[Callable[..., CoroutineType[Any, Any, Any]]]: ...
def iscoroutinefunction(obj: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...

def isgenerator(object: object) -> TypeIs[GeneratorType[object, Never, object]]: ...
def iscoroutine(object: object) -> TypeIs[CoroutineType[Any, Any, Any]]: ...
Expand All @@ -252,9 +252,9 @@ def isawaitable(object: object) -> TypeIs[Awaitable[Any]]: ...
@overload
def isasyncgenfunction(obj: Callable[..., AsyncGenerator[Any, Any]]) -> bool: ...
@overload
def isasyncgenfunction(obj: Callable[_P, Any]) -> TypeGuard[Callable[_P, AsyncGeneratorType[Any, Any]]]: ...
def isasyncgenfunction(obj: Callable[_P, Any]) -> TypeGuard[Callable[_P, AsyncGenerator[Any, Any]]]: ...
@overload
def isasyncgenfunction(obj: object) -> TypeGuard[Callable[..., AsyncGeneratorType[Any, Any]]]: ...
def isasyncgenfunction(obj: object) -> TypeGuard[Callable[..., AsyncGenerator[Any, Any]]]: ...

@type_check_only
class _SupportsSet(Protocol[_T_contra, _V_contra]):
Expand Down