Skip to content

Commit e2015f8

Browse files
authored
Merge pull request #380 from AlexWaygood/typing-extensions
Update typing rewrites for typing_extensions 4.12.0+
2 parents 64e79f3 + 1cadd2f commit e2015f8

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

reorder_python_imports.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def _fix_file(
421421
# Using:
422422
# flake8-typing-imports==1.15.0
423423
# mypy-extensions==1.0.0
424-
# typing-extensions==4.8.0
424+
# typing-extensions==4.12.1
425425
REPLACES[(3, 6)].update((
426426
'typing_extensions=typing:AbstractSet',
427427
'typing_extensions=typing:AnyStr',
@@ -433,12 +433,10 @@ def _fix_file(
433433
'typing_extensions=typing:ClassVar',
434434
'typing_extensions=typing:Collection',
435435
'typing_extensions=typing:Container',
436-
'typing_extensions=typing:ContextManager',
437436
'typing_extensions=typing:Coroutine',
438437
'typing_extensions=typing:DefaultDict',
439438
'typing_extensions=typing:Dict',
440439
'typing_extensions=typing:FrozenSet',
441-
'typing_extensions=typing:Generator',
442440
'typing_extensions=typing:Generic',
443441
'typing_extensions=typing:Hashable',
444442
'typing_extensions=typing:IO',
@@ -472,8 +470,6 @@ def _fix_file(
472470
))
473471
REPLACES[(3, 7)].update((
474472
'mypy_extensions=typing:NoReturn',
475-
'typing_extensions=typing:AsyncContextManager',
476-
'typing_extensions=typing:AsyncGenerator',
477473
'typing_extensions=typing:ChainMap',
478474
'typing_extensions=typing:Counter',
479475
'typing_extensions=typing:Deque',
@@ -484,8 +480,6 @@ def _fix_file(
484480
'mypy_extensions=typing:TypedDict',
485481
'typing_extensions=typing:Final',
486482
'typing_extensions=typing:OrderedDict',
487-
'typing_extensions=typing:SupportsIndex',
488-
'typing_extensions=typing:runtime_checkable',
489483
))
490484
REPLACES[(3, 9)].update((
491485
'typing_extensions=typing:Annotated',
@@ -520,15 +514,14 @@ def _fix_file(
520514
))
521515
REPLACES[(3, 12)].update((
522516
'typing_extensions=typing:NamedTuple',
523-
'typing_extensions=typing:Protocol',
524517
'typing_extensions=typing:SupportsAbs',
525518
'typing_extensions=typing:SupportsBytes',
526519
'typing_extensions=typing:SupportsComplex',
527520
'typing_extensions=typing:SupportsFloat',
521+
'typing_extensions=typing:SupportsIndex',
528522
'typing_extensions=typing:SupportsInt',
529523
'typing_extensions=typing:SupportsRound',
530524
'typing_extensions=typing:TypeAliasType',
531-
'typing_extensions=typing:TypedDict',
532525
'typing_extensions=typing:Unpack',
533526
'typing_extensions=typing:dataclass_transform',
534527
'typing_extensions=typing:override',

testing/generate-typing-rewrite-info

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,35 @@ import typing_extensions
2727
# - Any was change in Python 3.11 so it can be used as a base class
2828
# - From 3.11, NamedTuple and TypedDict can inherit from Generic;
2929
# from 3.12 onwards, the __orig_bases__ attribute
30-
# is properly set on NamedTuple and TypedDict classes
30+
# is properly set on NamedTuple and TypedDict classes.
31+
# From 3.13 onwards, TypedDict fields can be marked as `ReadOnly`.
3132
# - The frozen_default parameter was added to dataclass_transform in py312
3233
# - isinstance() checks are 20x faster or more for runtime-checkable protocols
33-
# on py312; typing_extensions backports the performance improvement
34+
# on py312; typing_extensions backports the performance improvement.
35+
# It also backports several bugfixes from early py312 patch releases.
3436
# - The repr of Unpack was changed in py312 as part of PEP 692;
3537
# typing_extensions backports this
3638
# - Python 3.12 adds the PEP 695 infer_variance parameter for TypeVar.
37-
# The PEP 696 default parameter for TypeVar, TypeVarTuple, and ParamSpec
38-
# is under consideration for Python 3.13.
39+
# - The PEP 696 default parameter for TypeVar, TypeVarTuple, and ParamSpec
40+
# has been added in Python 3.13.
41+
# - (Async)Generator now has a default value for all type parameters except
42+
# the first one on py313+, and (Async)ContextManager now has an optional
43+
# second parameter with a default value; typing_extensions backports these
44+
# changes.
3945
CUSTOM_TYPING_EXT_SYMBOLS = {
4046
(3, 9): {'get_type_hints'},
4147
(3, 10): {'get_origin', 'get_args', 'Literal', 'NewType'},
4248
(3, 11): {'Any', 'final', 'overload'},
4349
(3, 12): {
44-
'Protocol', 'SupportsInt', 'SupportsFloat', 'SupportsComplex',
50+
'SupportsInt', 'SupportsFloat', 'SupportsComplex',
4551
'SupportsBytes', 'SupportsAbs', 'SupportsRound', 'NamedTuple',
46-
'TypedDict', 'Unpack', 'dataclass_transform',
52+
'Unpack', 'dataclass_transform', 'SupportsIndex',
53+
},
54+
(3, 13): {
55+
'AsyncContextManager', 'ContextManager', 'AsyncGenerator', 'Generator',
56+
'TypeVar', 'TypeVarTuple', 'ParamSpec', 'TypedDict', 'Protocol',
57+
'runtime_checkable',
4758
},
48-
(3, 13): {'TypeVar', 'TypeVarTuple', 'ParamSpec'},
4959
}
5060

5161

0 commit comments

Comments
 (0)