Skip to content

Commit 30b7b67

Browse files
Give up on AnnotationForm in typing.pyi (#13999)
From #13985
1 parent 268a2e7 commit 30b7b67

File tree

1 file changed

+53
-39
lines changed

1 file changed

+53
-39
lines changed

stdlib/typing.pyi

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import collections # noqa: F401 # pyright: ignore[reportUnusedImport]
66
import sys
77
import typing_extensions
88
from _collections_abc import dict_items, dict_keys, dict_values
9-
from _typeshed import AnnotationForm, IdentityFunction, ReadableBuffer, SupportsKeysAndGetItem
9+
from _typeshed import IdentityFunction, ReadableBuffer, SupportsKeysAndGetItem
1010
from abc import ABCMeta, abstractmethod
1111
from re import Match as Match, Pattern as Pattern
1212
from types import (
@@ -142,6 +142,10 @@ if sys.version_info >= (3, 12):
142142
if sys.version_info >= (3, 13):
143143
__all__ += ["get_protocol_members", "is_protocol", "NoDefault", "TypeIs", "ReadOnly"]
144144

145+
# We can't use this name here because it leads to issues with mypy, likely
146+
# due to an import cycle. Below instead we use Any with a comment.
147+
# from _typeshed import AnnotationForm
148+
145149
class Any: ...
146150
class _Final: ...
147151

@@ -151,9 +155,9 @@ class TypeVar:
151155
@property
152156
def __name__(self) -> str: ...
153157
@property
154-
def __bound__(self) -> AnnotationForm | None: ...
158+
def __bound__(self) -> Any | None: ... # AnnotationForm
155159
@property
156-
def __constraints__(self) -> tuple[AnnotationForm, ...]: ...
160+
def __constraints__(self) -> tuple[Any, ...]: ... # AnnotationForm
157161
@property
158162
def __covariant__(self) -> bool: ...
159163
@property
@@ -163,24 +167,24 @@ class TypeVar:
163167
def __infer_variance__(self) -> bool: ...
164168
if sys.version_info >= (3, 13):
165169
@property
166-
def __default__(self) -> AnnotationForm: ...
170+
def __default__(self) -> Any: ... # AnnotationForm
167171
if sys.version_info >= (3, 13):
168172
def __new__(
169173
cls,
170174
name: str,
171-
*constraints: AnnotationForm,
172-
bound: AnnotationForm | None = None,
175+
*constraints: Any, # AnnotationForm
176+
bound: Any | None = None, # AnnotationForm
173177
contravariant: bool = False,
174178
covariant: bool = False,
175179
infer_variance: bool = False,
176-
default: AnnotationForm = ...,
180+
default: Any = ..., # AnnotationForm
177181
) -> Self: ...
178182
elif sys.version_info >= (3, 12):
179183
def __new__(
180184
cls,
181185
name: str,
182-
*constraints: AnnotationForm,
183-
bound: AnnotationForm | None = None,
186+
*constraints: Any, # AnnotationForm
187+
bound: Any | None = None, # AnnotationForm
184188
covariant: bool = False,
185189
contravariant: bool = False,
186190
infer_variance: bool = False,
@@ -189,23 +193,23 @@ class TypeVar:
189193
def __new__(
190194
cls,
191195
name: str,
192-
*constraints: AnnotationForm,
193-
bound: AnnotationForm | None = None,
196+
*constraints: Any, # AnnotationForm
197+
bound: Any | None = None, # AnnotationForm
194198
covariant: bool = False,
195199
contravariant: bool = False,
196200
) -> Self: ...
197201
else:
198202
def __init__(
199203
self,
200204
name: str,
201-
*constraints: AnnotationForm,
202-
bound: AnnotationForm | None = None,
205+
*constraints: Any, # AnnotationForm
206+
bound: Any | None = None, # AnnotationForm
203207
covariant: bool = False,
204208
contravariant: bool = False,
205209
) -> None: ...
206210
if sys.version_info >= (3, 10):
207-
def __or__(self, right: AnnotationForm) -> _SpecialForm: ...
208-
def __ror__(self, left: AnnotationForm) -> _SpecialForm: ...
211+
def __or__(self, right: Any) -> _SpecialForm: ... # AnnotationForm
212+
def __ror__(self, left: Any) -> _SpecialForm: ... # AnnotationForm
209213
if sys.version_info >= (3, 11):
210214
def __typing_subst__(self, arg: Any) -> Any: ...
211215
if sys.version_info >= (3, 13):
@@ -260,10 +264,10 @@ if sys.version_info >= (3, 11):
260264
def __name__(self) -> str: ...
261265
if sys.version_info >= (3, 13):
262266
@property
263-
def __default__(self) -> AnnotationForm: ...
267+
def __default__(self) -> Any: ... # AnnotationForm
264268
def has_default(self) -> bool: ...
265269
if sys.version_info >= (3, 13):
266-
def __new__(cls, name: str, *, default: AnnotationForm = ...) -> Self: ...
270+
def __new__(cls, name: str, *, default: Any = ...) -> Self: ... # AnnotationForm
267271
elif sys.version_info >= (3, 12):
268272
def __new__(cls, name: str) -> Self: ...
269273
else:
@@ -306,7 +310,7 @@ if sys.version_info >= (3, 10):
306310
@property
307311
def __name__(self) -> str: ...
308312
@property
309-
def __bound__(self) -> AnnotationForm | None: ...
313+
def __bound__(self) -> Any | None: ... # AnnotationForm
310314
@property
311315
def __covariant__(self) -> bool: ...
312316
@property
@@ -316,35 +320,45 @@ if sys.version_info >= (3, 10):
316320
def __infer_variance__(self) -> bool: ...
317321
if sys.version_info >= (3, 13):
318322
@property
319-
def __default__(self) -> AnnotationForm: ...
323+
def __default__(self) -> Any: ... # AnnotationForm
320324
if sys.version_info >= (3, 13):
321325
def __new__(
322326
cls,
323327
name: str,
324328
*,
325-
bound: AnnotationForm | None = None,
329+
bound: Any | None = None, # AnnotationForm
326330
contravariant: bool = False,
327331
covariant: bool = False,
328332
infer_variance: bool = False,
329-
default: AnnotationForm = ...,
333+
default: Any = ..., # AnnotationForm
330334
) -> Self: ...
331335
elif sys.version_info >= (3, 12):
332336
def __new__(
333337
cls,
334338
name: str,
335339
*,
336-
bound: AnnotationForm | None = None,
340+
bound: Any | None = None, # AnnotationForm
337341
contravariant: bool = False,
338342
covariant: bool = False,
339343
infer_variance: bool = False,
340344
) -> Self: ...
341345
elif sys.version_info >= (3, 11):
342346
def __new__(
343-
cls, name: str, *, bound: AnnotationForm | None = None, contravariant: bool = False, covariant: bool = False
347+
cls,
348+
name: str,
349+
*,
350+
bound: Any | None = None, # AnnotationForm
351+
contravariant: bool = False,
352+
covariant: bool = False,
344353
) -> Self: ...
345354
else:
346355
def __init__(
347-
self, name: str, *, bound: AnnotationForm | None = None, contravariant: bool = False, covariant: bool = False
356+
self,
357+
name: str,
358+
*,
359+
bound: Any | None = None, # AnnotationForm
360+
contravariant: bool = False,
361+
covariant: bool = False,
348362
) -> None: ...
349363

350364
@property
@@ -368,7 +382,7 @@ if sys.version_info >= (3, 10):
368382
TypeGuard: _SpecialForm
369383

370384
class NewType:
371-
def __init__(self, name: str, tp: AnnotationForm) -> None: ...
385+
def __init__(self, name: str, tp: Any) -> None: ... # AnnotationForm
372386
if sys.version_info >= (3, 11):
373387
@staticmethod
374388
def __call__(x: _T, /) -> _T: ...
@@ -901,17 +915,17 @@ if sys.version_info >= (3, 14):
901915
include_extras: bool = False,
902916
*,
903917
format: Format | None = None,
904-
) -> dict[str, AnnotationForm]: ...
918+
) -> dict[str, Any]: ... # AnnotationForm
905919

906920
else:
907921
def get_type_hints(
908922
obj: _get_type_hints_obj_allowed_types,
909923
globalns: dict[str, Any] | None = None,
910924
localns: Mapping[str, Any] | None = None,
911925
include_extras: bool = False,
912-
) -> dict[str, AnnotationForm]: ...
926+
) -> dict[str, Any]: ... # AnnotationForm
913927

914-
def get_args(tp: AnnotationForm) -> tuple[AnnotationForm, ...]: ...
928+
def get_args(tp: Any) -> tuple[Any, ...]: ... # AnnotationForm
915929

916930
if sys.version_info >= (3, 10):
917931
@overload
@@ -922,7 +936,7 @@ if sys.version_info >= (3, 10):
922936
@overload
923937
def get_origin(tp: GenericAlias) -> type: ...
924938
@overload
925-
def get_origin(tp: AnnotationForm) -> AnnotationForm | None: ...
939+
def get_origin(tp: Any) -> Any | None: ... # AnnotationForm
926940
@overload
927941
def cast(typ: type[_T], val: Any) -> _T: ...
928942
@overload
@@ -933,7 +947,7 @@ def cast(typ: object, val: Any) -> Any: ...
933947
if sys.version_info >= (3, 11):
934948
def reveal_type(obj: _T, /) -> _T: ...
935949
def assert_never(arg: Never, /) -> Never: ...
936-
def assert_type(val: _T, typ: AnnotationForm, /) -> _T: ...
950+
def assert_type(val: _T, typ: Any, /) -> _T: ... # AnnotationForm
937951
def clear_overloads() -> None: ...
938952
def get_overloads(func: Callable[..., object]) -> Sequence[Callable[..., object]]: ...
939953
def dataclass_transform(
@@ -1020,15 +1034,15 @@ if sys.version_info >= (3, 14):
10201034
locals: Mapping[str, Any] | None = None,
10211035
type_params: tuple[TypeVar, ParamSpec, TypeVarTuple] | None = None,
10221036
format: Format | None = None,
1023-
) -> AnnotationForm: ...
1037+
) -> Any: ... # AnnotationForm
10241038

10251039
else:
10261040
@final
10271041
class ForwardRef(_Final):
10281042
__forward_arg__: str
10291043
__forward_code__: CodeType
10301044
__forward_evaluated__: bool
1031-
__forward_value__: AnnotationForm | None
1045+
__forward_value__: Any | None # AnnotationForm
10321046
__forward_is_argument__: bool
10331047
__forward_is_class__: bool
10341048
__forward_module__: Any | None
@@ -1044,7 +1058,7 @@ else:
10441058
)
10451059
def _evaluate(
10461060
self, globalns: dict[str, Any] | None, localns: Mapping[str, Any] | None, *, recursive_guard: frozenset[str]
1047-
) -> AnnotationForm | None: ...
1061+
) -> Any | None: ... # AnnotationForm
10481062
@overload
10491063
def _evaluate(
10501064
self,
@@ -1053,7 +1067,7 @@ else:
10531067
type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...],
10541068
*,
10551069
recursive_guard: frozenset[str],
1056-
) -> AnnotationForm | None: ...
1070+
) -> Any | None: ... # AnnotationForm
10571071
elif sys.version_info >= (3, 12):
10581072
def _evaluate(
10591073
self,
@@ -1062,11 +1076,11 @@ else:
10621076
type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] | None = None,
10631077
*,
10641078
recursive_guard: frozenset[str],
1065-
) -> AnnotationForm | None: ...
1079+
) -> Any | None: ... # AnnotationForm
10661080
else:
10671081
def _evaluate(
10681082
self, globalns: dict[str, Any] | None, localns: Mapping[str, Any] | None, recursive_guard: frozenset[str]
1069-
) -> AnnotationForm | None: ...
1083+
) -> Any | None: ... # AnnotationForm
10701084

10711085
def __eq__(self, other: object) -> bool: ...
10721086
def __hash__(self) -> int: ...
@@ -1085,17 +1099,17 @@ if sys.version_info >= (3, 12):
10851099
class TypeAliasType:
10861100
def __new__(cls, name: str, value: Any, *, type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ()) -> Self: ...
10871101
@property
1088-
def __value__(self) -> AnnotationForm: ...
1102+
def __value__(self) -> Any: ... # AnnotationForm
10891103
@property
10901104
def __type_params__(self) -> tuple[TypeVar | ParamSpec | TypeVarTuple, ...]: ...
10911105
@property
1092-
def __parameters__(self) -> tuple[AnnotationForm, ...]: ...
1106+
def __parameters__(self) -> tuple[Any, ...]: ... # AnnotationForm
10931107
@property
10941108
def __name__(self) -> str: ...
10951109
# It's writable on types, but not on instances of TypeAliasType.
10961110
@property
10971111
def __module__(self) -> str | None: ... # type: ignore[override]
1098-
def __getitem__(self, parameters: AnnotationForm) -> GenericAlias: ...
1112+
def __getitem__(self, parameters: Any) -> GenericAlias: ... # AnnotationForm
10991113
def __or__(self, right: Any) -> _SpecialForm: ...
11001114
def __ror__(self, left: Any) -> _SpecialForm: ...
11011115
if sys.version_info >= (3, 14):

0 commit comments

Comments
 (0)