Skip to content

Commit e46fa3c

Browse files
committed
Avoid Any specializations for covariant and contravariant type variables inside TypeIs returns
1 parent f97c785 commit e46fa3c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

stdlib/asyncio/coroutines.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from collections.abc import Awaitable, Callable, Coroutine
33
from typing import Any, TypeVar, overload
4-
from typing_extensions import ParamSpec, TypeGuard, TypeIs, deprecated
4+
from typing_extensions import Never, ParamSpec, TypeGuard, TypeIs, deprecated
55

66
# Keep asyncio.__all__ updated with any changes to __all__ here
77
if sys.version_info >= (3, 11):
@@ -25,4 +25,4 @@ def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable
2525
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
2626
@overload
2727
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...
28-
def iscoroutine(obj: object) -> TypeIs[Coroutine[Any, Any, Any]]: ...
28+
def iscoroutine(obj: object) -> TypeIs[Coroutine[object, Never, object]]: ...

stdlib/inspect.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ from types import (
2626
WrapperDescriptorType,
2727
)
2828
from typing import Any, ClassVar, Final, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only
29-
from typing_extensions import ParamSpec, Self, TypeAlias, TypeGuard, TypeIs, deprecated, disjoint_base
29+
from typing_extensions import Never, ParamSpec, Self, TypeAlias, TypeGuard, TypeIs, deprecated, disjoint_base
3030

3131
if sys.version_info >= (3, 14):
3232
from annotationlib import Format
@@ -205,7 +205,7 @@ if sys.version_info >= (3, 11):
205205

206206
def getmodulename(path: StrPath) -> str | None: ...
207207
def ismodule(object: object) -> TypeIs[ModuleType]: ...
208-
def isclass(object: object) -> TypeIs[type[Any]]: ...
208+
def isclass(object: object) -> TypeIs[type[object]]: ...
209209
def ismethod(object: object) -> TypeIs[MethodType]: ...
210210

211211
if sys.version_info >= (3, 14):
@@ -231,9 +231,9 @@ def iscoroutinefunction(obj: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[
231231
def iscoroutinefunction(obj: Callable[_P, object]) -> TypeGuard[Callable[_P, CoroutineType[Any, Any, Any]]]: ...
232232
@overload
233233
def iscoroutinefunction(obj: object) -> TypeGuard[Callable[..., CoroutineType[Any, Any, Any]]]: ...
234-
def isgenerator(object: object) -> TypeIs[GeneratorType[Any, Any, Any]]: ...
235-
def iscoroutine(object: object) -> TypeIs[CoroutineType[Any, Any, Any]]: ...
236-
def isawaitable(object: object) -> TypeIs[Awaitable[Any]]: ...
234+
def isgenerator(object: object) -> TypeIs[GeneratorType[object, Never, object]]: ...
235+
def iscoroutine(object: object) -> TypeIs[CoroutineType[object, Never, object]]: ...
236+
def isawaitable(object: object) -> TypeIs[Awaitable[object]]: ...
237237
@overload
238238
def isasyncgenfunction(obj: Callable[..., AsyncGenerator[Any, Any]]) -> bool: ...
239239
@overload
@@ -248,7 +248,7 @@ class _SupportsSet(Protocol[_T_contra, _V_contra]):
248248
class _SupportsDelete(Protocol[_T_contra]):
249249
def __delete__(self, instance: _T_contra, /) -> None: ...
250250

251-
def isasyncgen(object: object) -> TypeIs[AsyncGeneratorType[Any, Any]]: ...
251+
def isasyncgen(object: object) -> TypeIs[AsyncGeneratorType[object, Never]]: ...
252252
def istraceback(object: object) -> TypeIs[TracebackType]: ...
253253
def isframe(object: object) -> TypeIs[FrameType]: ...
254254
def iscode(object: object) -> TypeIs[CodeType]: ...
@@ -273,7 +273,7 @@ def ismethoddescriptor(object: object) -> TypeIs[MethodDescriptorType]: ...
273273
def ismemberdescriptor(object: object) -> TypeIs[MemberDescriptorType]: ...
274274
def isabstract(object: object) -> bool: ...
275275
def isgetsetdescriptor(object: object) -> TypeIs[GetSetDescriptorType]: ...
276-
def isdatadescriptor(object: object) -> TypeIs[_SupportsSet[Any, Any] | _SupportsDelete[Any]]: ...
276+
def isdatadescriptor(object: object) -> TypeIs[_SupportsSet[Never, Never] | _SupportsDelete[Never]]: ...
277277

278278
#
279279
# Retrieving source code

0 commit comments

Comments
 (0)