Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only rewrite typing.Callable in 3.10+ #679

Merged
merged 1 commit into from Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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