Skip to content

Commit 4ef3bf2

Browse files
committed
Feedback
1 parent 2ac1d8c commit 4ef3bf2

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/test_typing_extensions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5157,7 +5157,7 @@ class C:
51575157
A.x = 5
51585158
self.assertEqual(C.x, 5)
51595159

5160-
@skipIf(sys.version_info[:2] == (3, 10), "Waiting for bpo-46491 bugfix.")
5160+
@skipIf(sys.version_info[:2] == (3, 10), "Waiting for https://github.com/python/cpython/issues/90649 bugfix.")
51615161
def test_special_form_containment(self):
51625162
class C:
51635163
classvar: Annotated[ClassVar[int], "a decoration"] = 4
@@ -5482,7 +5482,7 @@ def test_valid_uses(self):
54825482
self.assertTrue(hasattr(P, 'args'))
54835483
self.assertTrue(hasattr(P, 'kwargs'))
54845484

5485-
@skipIf((3, 10, 0) <= sys.version_info[:3] <= (3, 10, 2), "Needs bpo-46676.")
5485+
@skipIf((3, 10, 0) <= sys.version_info[:3] <= (3, 10, 2), "Needs https://github.com/python/cpython/issues/90834.")
54865486
def test_args_kwargs(self):
54875487
P = ParamSpec('P')
54885488
P_2 = ParamSpec('P_2')
@@ -7202,7 +7202,7 @@ def test_bound_errors(self):
72027202
TypeVar('X', bound=(1, 2))
72037203

72047204
def test_missing__name__(self):
7205-
# See bpo-39942
7205+
# See https://github.com/python/cpython/issues/84123
72067206
code = ("import typing\n"
72077207
"T = typing.TypeVar('T')\n"
72087208
)

src/typing_extensions.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pyright: ignore
12
import abc
23
import builtins
34
import collections
@@ -568,7 +569,7 @@ class _ProtocolMeta(type(typing.Protocol)):
568569
# but is necessary for several reasons...
569570
#
570571
# NOTE: DO NOT call super() in any methods in this class
571-
# That would call the methods on typing._ProtocolMeta on Python 3.9-3.11
572+
# That would call the methods on typing._ProtocolMeta on Python <=3.11
572573
# and those are slow
573574
def __new__(mcls, name, bases, namespace, **kwargs):
574575
if name == "Protocol" and len(bases) < 2:
@@ -769,7 +770,7 @@ def close(self): ...
769770
runtime = runtime_checkable
770771

771772

772-
# Our version of runtime-checkable protocols is faster on Python 3.9-3.11
773+
# Our version of runtime-checkable protocols is faster on Python <=3.11
773774
if sys.version_info >= (3, 12):
774775
SupportsInt = typing.SupportsInt
775776
SupportsFloat = typing.SupportsFloat
@@ -1182,7 +1183,7 @@ class Point2D(TypedDict):
11821183
td.__orig_bases__ = (TypedDict,)
11831184
return td
11841185

1185-
_TYPEDDICT_TYPES = (typing._TypedDictMeta, _TypedDictMeta,)
1186+
_TYPEDDICT_TYPES = (typing._TypedDictMeta, _TypedDictMeta)
11861187

11871188
def is_typeddict(tp):
11881189
"""Check if an annotation is a TypedDict class
@@ -1291,8 +1292,7 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False):
12911292

12921293
def _could_be_inserted_optional(t):
12931294
"""detects Union[..., None] pattern"""
1294-
# 3.8+ compatible checking before _UnionGenericAlias
1295-
if get_origin(t) is not Union:
1295+
if not isinstance(t, typing._UnionGenericAlias):
12961296
return False
12971297
# Assume if last argument is not None they are user defined
12981298
if t.__args__[-1] is not _NoneType:
@@ -1336,11 +1336,11 @@ def _clean_optional(obj, hints, globalns=None, localns=None):
13361336
localns = globalns
13371337
elif localns is None:
13381338
localns = globalns
1339-
else:
1340-
original_value = ForwardRef(
1341-
original_value,
1342-
is_argument=not isinstance(obj, _types.ModuleType)
1343-
)
1339+
1340+
original_value = ForwardRef(
1341+
original_value,
1342+
is_argument=not isinstance(obj, _types.ModuleType)
1343+
)
13441344
original_evaluated = typing._eval_type(original_value, globalns, localns)
13451345
# Compare if values differ. Note that even if equal
13461346
# value might be cached by typing._tp_cache contrary to original_evaluated
@@ -1359,7 +1359,6 @@ def _clean_optional(obj, hints, globalns=None, localns=None):
13591359
get_args = typing.get_args
13601360
# 3.9
13611361
else:
1362-
from typing import GenericAlias as _typing_GenericAlias
13631362
from typing import _AnnotatedAlias, _BaseGenericAlias
13641363

13651364
def get_origin(tp):
@@ -1379,7 +1378,7 @@ def get_origin(tp):
13791378
"""
13801379
if isinstance(tp, _AnnotatedAlias):
13811380
return Annotated
1382-
if isinstance(tp, (_typing_GenericAlias, _BaseGenericAlias,
1381+
if isinstance(tp, (_types.GenericAlias, _BaseGenericAlias,
13831382
ParamSpecArgs, ParamSpecKwargs)):
13841383
return tp.__origin__
13851384
if tp is typing.Generic:
@@ -1399,7 +1398,7 @@ def get_args(tp):
13991398
"""
14001399
if isinstance(tp, _AnnotatedAlias):
14011400
return (tp.__origin__, *tp.__metadata__)
1402-
if isinstance(tp, (typing._GenericAlias, _typing_GenericAlias)):
1401+
if isinstance(tp, (typing._GenericAlias, _types.GenericAlias)):
14031402
res = tp.__args__
14041403
if get_origin(tp) is collections.abc.Callable and res[0] is not Ellipsis:
14051404
res = (list(res[:-1]), res[-1])
@@ -1882,7 +1881,7 @@ def __getitem__(self, args):
18821881
class _EllipsisDummy: ...
18831882

18841883

1885-
# 3.9-3.10
1884+
# <=3.10
18861885
def _create_concatenate_alias(origin, parameters):
18871886
if parameters[-1] is ... and sys.version_info < (3, 9, 2):
18881887
# Hack: Arguments must be types, replace it with one.
@@ -1906,7 +1905,7 @@ def _create_concatenate_alias(origin, parameters):
19061905
return concatenate
19071906

19081907

1909-
# 3.9-3.10
1908+
# <=3.10
19101909
@typing._tp_cache
19111910
def _concatenate_getitem(self, parameters):
19121911
if parameters == ():
@@ -1925,7 +1924,7 @@ def _concatenate_getitem(self, parameters):
19251924
# 3.11+; Concatenate does not accept ellipsis in 3.10
19261925
if sys.version_info >= (3, 11):
19271926
Concatenate = typing.Concatenate
1928-
# 3.9-3.10
1927+
# <=3.10
19291928
else:
19301929
@_ExtensionsSpecialForm
19311930
def Concatenate(self, parameters):
@@ -1998,7 +1997,7 @@ def is_str(val: Union[str, float]):
19981997
# 3.13+
19991998
if hasattr(typing, 'TypeIs'):
20001999
TypeIs = typing.TypeIs
2001-
# 3.9
2000+
# <=3.12
20022001
else:
20032002
@_ExtensionsSpecialForm
20042003
def TypeIs(self, parameters):
@@ -2045,7 +2044,7 @@ def f(val: Union[int, Awaitable[int]]) -> int:
20452044
# 3.14+?
20462045
if hasattr(typing, 'TypeForm'):
20472046
TypeForm = typing.TypeForm
2048-
# 3.9
2047+
# <=3.13
20492048
else:
20502049
class _TypeFormForm(_ExtensionsSpecialForm, _root=True):
20512050
# TypeForm(X) is equivalent to X but indicates to the type checker
@@ -2197,7 +2196,7 @@ def int_or_str(arg: int | str) -> None:
21972196
if hasattr(typing, 'Required'): # 3.11+
21982197
Required = typing.Required
21992198
NotRequired = typing.NotRequired
2200-
else: # 3.9-3.10
2199+
else: # <=3.10
22012200
@_ExtensionsSpecialForm
22022201
def Required(self, parameters):
22032202
"""A special typing construct to mark a key of a total=False TypedDict
@@ -2238,7 +2237,7 @@ class Movie(TypedDict):
22382237

22392238
if hasattr(typing, 'ReadOnly'):
22402239
ReadOnly = typing.ReadOnly
2241-
else: # 3.9-3.12
2240+
else: # <=3.12
22422241
@_ExtensionsSpecialForm
22432242
def ReadOnly(self, parameters):
22442243
"""A special typing construct to mark an item of a TypedDict as read-only.
@@ -2307,7 +2306,7 @@ def foo(**kwargs: Unpack[Movie]): ...
23072306
def _is_unpack(obj):
23082307
return get_origin(obj) is Unpack
23092308

2310-
else: # 3.9+
2309+
else: # <=3.11
23112310
class _UnpackSpecialForm(_ExtensionsSpecialForm, _root=True):
23122311
def __init__(self, getitem):
23132312
super().__init__(getitem)
@@ -3394,10 +3393,10 @@ def __ror__(self, other):
33943393

33953394
if sys.version_info >= (3, 14):
33963395
TypeAliasType = typing.TypeAliasType
3397-
# 3.8-3.13
3396+
# <=3.13
33983397
else:
33993398
if sys.version_info >= (3, 12):
3400-
# 3.12-3.14
3399+
# 3.12-3.13
34013400
def _is_unionable(obj):
34023401
"""Corresponds to is_unionable() in unionobject.c in CPython."""
34033402
return obj is None or isinstance(obj, (
@@ -3408,7 +3407,7 @@ def _is_unionable(obj):
34083407
TypeAliasType,
34093408
))
34103409
else:
3411-
# 3.9-3.11
3410+
# <=3.11
34123411
def _is_unionable(obj):
34133412
"""Corresponds to is_unionable() in unionobject.c in CPython."""
34143413
return obj is None or isinstance(obj, (
@@ -3485,7 +3484,7 @@ def __init__(self, name: str, value, *, type_params=()):
34853484
for type_param in type_params:
34863485
if (
34873486
not isinstance(type_param, (TypeVar, TypeVarTuple, ParamSpec))
3488-
# 3.9-3.11
3487+
# <=3.11
34893488
# Unpack Backport passes isinstance(type_param, TypeVar)
34903489
or _is_unpack(type_param)
34913490
):

0 commit comments

Comments
 (0)