Skip to content

Commit 6ef17c3

Browse files
authored
Merge pull request #679 from asottile/typing-callable
only rewrite typing.Callable in 3.10+
2 parents 8eb196d + 44742d8 commit 6ef17c3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pyupgrade/_plugins/imports.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pyupgrade._token_helpers import indented_amount
2121

2222
# GENERATED VIA generate-imports
23-
# Using reorder-python-imports==3.8.0
23+
# Using reorder-python-imports==3.8.1
2424
REMOVALS = {
2525
(2, 7): {'__future__': {'generators', 'nested_scopes', 'with_statement'}},
2626
(3,): {
@@ -130,7 +130,6 @@
130130
('typing', 'AsyncIterator'): 'collections.abc',
131131
('typing', 'Awaitable'): 'collections.abc',
132132
('typing', 'ByteString'): 'collections.abc',
133-
('typing', 'Callable'): 'collections.abc',
134133
('typing', 'ChainMap'): 'collections',
135134
('typing', 'Collection'): 'collections.abc',
136135
('typing', 'Container'): 'collections.abc',
@@ -159,6 +158,7 @@
159158
('typing_extensions', 'Annotated'): 'typing',
160159
},
161160
(3, 10): {
161+
('typing', 'Callable'): 'collections.abc',
162162
('typing_extensions', 'Concatenate'): 'typing',
163163
('typing_extensions', 'ParamSpec'): 'typing',
164164
('typing_extensions', 'TypeAlias'): 'typing',

tests/features/import_replaces_test.py

+11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
(3,),
4646
id='from import of module without alias',
4747
),
48+
pytest.param(
49+
'from typing import Callable\n',
50+
(3, 9),
51+
id='skip rewriting of Callable in 3.9 since it is broken',
52+
),
4853
),
4954
)
5055
def test_import_replaces_noop(s, min_version):
@@ -283,6 +288,12 @@ def test_mock_noop_keep_mock():
283288
'from unittest import mock\n',
284289
id='mock import mock import',
285290
),
291+
pytest.param(
292+
'from typing import Callable\n',
293+
(3, 10),
294+
'from collections.abc import Callable\n',
295+
id='typing.Callable is rewritable in 3.10+ only',
296+
),
286297
),
287298
)
288299
def test_import_replaces(s, min_version, expected):

0 commit comments

Comments
 (0)