diff --git a/pyupgrade/_plugins/imports.py b/pyupgrade/_plugins/imports.py index 6d24864a..df54d6e5 100644 --- a/pyupgrade/_plugins/imports.py +++ b/pyupgrade/_plugins/imports.py @@ -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,): { @@ -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', @@ -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', diff --git a/tests/features/import_replaces_test.py b/tests/features/import_replaces_test.py index d53acbe0..d0523084 100644 --- a/tests/features/import_replaces_test.py +++ b/tests/features/import_replaces_test.py @@ -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): @@ -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):