Skip to content

Commit

Permalink
only rewrite typing.Callabe in 3.10+
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jul 11, 2022
1 parent 8eb196d commit 55b0675
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyupgrade/_plugins/imports.py
Expand Up @@ -20,7 +20,7 @@
from pyupgrade._token_helpers import indented_amount

# GENERATED VIA generate-imports
# Using reorder-python-imports==3.8.0
# Using reorder-python-imports==3.8.1
REMOVALS = {
(2, 7): {'__future__': {'generators', 'nested_scopes', 'with_statement'}},
(3,): {
Expand Down Expand Up @@ -130,7 +130,6 @@
('typing', 'AsyncIterator'): 'collections.abc',
('typing', 'Awaitable'): 'collections.abc',
('typing', 'ByteString'): 'collections.abc',
('typing', 'Callable'): 'collections.abc',
('typing', 'ChainMap'): 'collections',
('typing', 'Collection'): 'collections.abc',
('typing', 'Container'): 'collections.abc',
Expand Down Expand Up @@ -159,6 +158,7 @@
('typing_extensions', 'Annotated'): 'typing',
},
(3, 10): {
('typing', 'Callable'): 'collections.abc',
('typing_extensions', 'Concatenate'): 'typing',
('typing_extensions', 'ParamSpec'): 'typing',
('typing_extensions', 'TypeAlias'): 'typing',
Expand Down
11 changes: 11 additions & 0 deletions tests/features/import_replaces_test.py
Expand Up @@ -45,6 +45,11 @@
(3,),
id='from import of module without alias',
),
pytest.param(
'from typing import Callable\n',
(3, 9),
id='skip rewriting of Callable in 3.9 since it is broken',
),
),
)
def test_import_replaces_noop(s, min_version):
Expand Down Expand Up @@ -283,6 +288,12 @@ def test_mock_noop_keep_mock():
'from unittest import mock\n',
id='mock import mock import',
),
pytest.param(
'from typing import Callable\n',
(3, 10),
'from collections.abc import Callable\n',
id='typing.Callable is rewritable in 3.10+ only',
),
),
)
def test_import_replaces(s, min_version, expected):
Expand Down

0 comments on commit 55b0675

Please sign in to comment.