diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 530b40c1..b3b02345 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: rev: v3.13.0 hooks: - id: reorder-python-imports - args: [--py38-plus, --add-import, 'from __future__ import annotations'] + args: [--py39-plus, --add-import, 'from __future__ import annotations'] - repo: https://github.com/asottile/add-trailing-comma rev: v3.1.0 hooks: @@ -26,7 +26,7 @@ repos: rev: v3.18.0 hooks: - id: pyupgrade - args: [--py38-plus] + args: [--py39-plus] - repo: https://github.com/hhatto/autopep8 rev: v2.3.1 hooks: diff --git a/pyupgrade/_ast_helpers.py b/pyupgrade/_ast_helpers.py index 8a79d3ab..9763d060 100644 --- a/pyupgrade/_ast_helpers.py +++ b/pyupgrade/_ast_helpers.py @@ -2,7 +2,7 @@ import ast import warnings -from typing import Container +from collections.abc import Container from tokenize_rt import Offset diff --git a/pyupgrade/_data.py b/pyupgrade/_data.py index 3f1efe8a..164d30b2 100644 --- a/pyupgrade/_data.py +++ b/pyupgrade/_data.py @@ -3,12 +3,10 @@ import ast import collections import pkgutil +from collections.abc import Iterable from typing import Callable -from typing import Iterable -from typing import List from typing import NamedTuple from typing import Protocol -from typing import Tuple from typing import TypeVar from tokenize_rt import Offset @@ -16,7 +14,7 @@ from pyupgrade import _plugins -Version = Tuple[int, ...] +Version = tuple[int, ...] class Settings(NamedTuple): @@ -33,8 +31,8 @@ class State(NamedTuple): AST_T = TypeVar('AST_T', bound=ast.AST) -TokenFunc = Callable[[int, List[Token]], None] -ASTFunc = Callable[[State, AST_T, ast.AST], Iterable[Tuple[Offset, TokenFunc]]] +TokenFunc = Callable[[int, list[Token]], None] +ASTFunc = Callable[[State, AST_T, ast.AST], Iterable[tuple[Offset, TokenFunc]]] RECORD_FROM_IMPORTS = frozenset(( '__future__', diff --git a/pyupgrade/_main.py b/pyupgrade/_main.py index 4ac91810..e52b9c66 100644 --- a/pyupgrade/_main.py +++ b/pyupgrade/_main.py @@ -5,8 +5,8 @@ import re import sys import tokenize -from typing import Match -from typing import Sequence +from collections.abc import Sequence +from re import Match from tokenize_rt import NON_CODING_TOKENS from tokenize_rt import parse_string_literal diff --git a/pyupgrade/_plugins/collections_abc.py b/pyupgrade/_plugins/collections_abc.py index f7e879e3..a4bcb10b 100644 --- a/pyupgrade/_plugins/collections_abc.py +++ b/pyupgrade/_plugins/collections_abc.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/constant_fold.py b/pyupgrade/_plugins/constant_fold.py index 07c3de54..5411b95f 100644 --- a/pyupgrade/_plugins/constant_fold.py +++ b/pyupgrade/_plugins/constant_fold.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/datetime_utc_alias.py b/pyupgrade/_plugins/datetime_utc_alias.py index 5280e5db..8c511533 100644 --- a/pyupgrade/_plugins/datetime_utc_alias.py +++ b/pyupgrade/_plugins/datetime_utc_alias.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/defauldict_lambda.py b/pyupgrade/_plugins/defauldict_lambda.py index 1cfa7464..1d6bb0a9 100644 --- a/pyupgrade/_plugins/defauldict_lambda.py +++ b/pyupgrade/_plugins/defauldict_lambda.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/default_encoding.py b/pyupgrade/_plugins/default_encoding.py index ab24b9ca..f681510d 100644 --- a/pyupgrade/_plugins/default_encoding.py +++ b/pyupgrade/_plugins/default_encoding.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/dict_literals.py b/pyupgrade/_plugins/dict_literals.py index c87e9e89..ca4a2860 100644 --- a/pyupgrade/_plugins/dict_literals.py +++ b/pyupgrade/_plugins/dict_literals.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/exceptions.py b/pyupgrade/_plugins/exceptions.py index 37b39faa..4018ebbb 100644 --- a/pyupgrade/_plugins/exceptions.py +++ b/pyupgrade/_plugins/exceptions.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from typing import NamedTuple from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/format_locals.py b/pyupgrade/_plugins/format_locals.py index cc63c442..af4ae475 100644 --- a/pyupgrade/_plugins/format_locals.py +++ b/pyupgrade/_plugins/format_locals.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import rfind_string_parts diff --git a/pyupgrade/_plugins/fstrings.py b/pyupgrade/_plugins/fstrings.py index e6480756..d9359650 100644 --- a/pyupgrade/_plugins/fstrings.py +++ b/pyupgrade/_plugins/fstrings.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import parse_string_literal diff --git a/pyupgrade/_plugins/identity_equality.py b/pyupgrade/_plugins/identity_equality.py index 2f0d5fd4..9a23c5ec 100644 --- a/pyupgrade/_plugins/identity_equality.py +++ b/pyupgrade/_plugins/identity_equality.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/imports.py b/pyupgrade/_plugins/imports.py index dbd44e77..cb7ae93b 100644 --- a/pyupgrade/_plugins/imports.py +++ b/pyupgrade/_plugins/imports.py @@ -4,8 +4,8 @@ import bisect import collections import functools -from typing import Iterable -from typing import Mapping +from collections.abc import Iterable +from collections.abc import Mapping from typing import NamedTuple from tokenize_rt import Offset @@ -298,7 +298,7 @@ # END GENERATED -@functools.lru_cache(maxsize=None) +@functools.cache def _for_version( version: tuple[int, ...], *, diff --git a/pyupgrade/_plugins/io_open.py b/pyupgrade/_plugins/io_open.py index 72fe4493..da20a3d4 100644 --- a/pyupgrade/_plugins/io_open.py +++ b/pyupgrade/_plugins/io_open.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/legacy.py b/pyupgrade/_plugins/legacy.py index 98a6dd61..f79219ff 100644 --- a/pyupgrade/_plugins/legacy.py +++ b/pyupgrade/_plugins/legacy.py @@ -4,9 +4,9 @@ import collections import contextlib import functools +from collections.abc import Generator +from collections.abc import Iterable from typing import Any -from typing import Generator -from typing import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/lru_cache.py b/pyupgrade/_plugins/lru_cache.py index 6d690ecb..cec153f0 100644 --- a/pyupgrade/_plugins/lru_cache.py +++ b/pyupgrade/_plugins/lru_cache.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/metaclass_type.py b/pyupgrade/_plugins/metaclass_type.py index 5749050a..0010cf3b 100644 --- a/pyupgrade/_plugins/metaclass_type.py +++ b/pyupgrade/_plugins/metaclass_type.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/mock.py b/pyupgrade/_plugins/mock.py index 0e1c391b..bfae7024 100644 --- a/pyupgrade/_plugins/mock.py +++ b/pyupgrade/_plugins/mock.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/native_literals.py b/pyupgrade/_plugins/native_literals.py index ba535d64..90d0e390 100644 --- a/pyupgrade/_plugins/native_literals.py +++ b/pyupgrade/_plugins/native_literals.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/new_style_classes.py b/pyupgrade/_plugins/new_style_classes.py index f0bb6f4e..6535a5a7 100644 --- a/pyupgrade/_plugins/new_style_classes.py +++ b/pyupgrade/_plugins/new_style_classes.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/open_mode.py b/pyupgrade/_plugins/open_mode.py index f0bfc98c..17730afb 100644 --- a/pyupgrade/_plugins/open_mode.py +++ b/pyupgrade/_plugins/open_mode.py @@ -3,7 +3,7 @@ import ast import functools import itertools -from typing import Iterable +from collections.abc import Iterable from typing import NamedTuple from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/percent_format.py b/pyupgrade/_plugins/percent_format.py index 0d38fede..effc4ddd 100644 --- a/pyupgrade/_plugins/percent_format.py +++ b/pyupgrade/_plugins/percent_format.py @@ -3,12 +3,11 @@ import ast import functools import re -from typing import Generator -from typing import Iterable -from typing import Match +from collections.abc import Generator +from collections.abc import Iterable +from re import Match +from re import Pattern from typing import Optional -from typing import Pattern -from typing import Tuple from tokenize_rt import Offset from tokenize_rt import Token @@ -23,14 +22,14 @@ from pyupgrade._token_helpers import remove_brace from pyupgrade._token_helpers import victims -PercentFormatPart = Tuple[ +PercentFormatPart = tuple[ Optional[str], Optional[str], Optional[str], Optional[str], str, ] -PercentFormat = Tuple[str, Optional[PercentFormatPart]] +PercentFormat = tuple[str, Optional[PercentFormatPart]] MAPPING_KEY_RE = re.compile(r'\(([^()]*)\)') CONVERSION_FLAG_RE = re.compile('[#0+ -]*') diff --git a/pyupgrade/_plugins/set_literals.py b/pyupgrade/_plugins/set_literals.py index 631dc88a..e3369ae4 100644 --- a/pyupgrade/_plugins/set_literals.py +++ b/pyupgrade/_plugins/set_literals.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/shlex_join.py b/pyupgrade/_plugins/shlex_join.py index 1718ff9a..ddd5824a 100644 --- a/pyupgrade/_plugins/shlex_join.py +++ b/pyupgrade/_plugins/shlex_join.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import NON_CODING_TOKENS from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/six_base_classes.py b/pyupgrade/_plugins/six_base_classes.py index 77008bce..789fca6f 100644 --- a/pyupgrade/_plugins/six_base_classes.py +++ b/pyupgrade/_plugins/six_base_classes.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/six_calls.py b/pyupgrade/_plugins/six_calls.py index 2434a66f..7bddce84 100644 --- a/pyupgrade/_plugins/six_calls.py +++ b/pyupgrade/_plugins/six_calls.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/six_metaclasses.py b/pyupgrade/_plugins/six_metaclasses.py index 9d9e6eb9..b2d47311 100644 --- a/pyupgrade/_plugins/six_metaclasses.py +++ b/pyupgrade/_plugins/six_metaclasses.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import NON_CODING_TOKENS from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/six_remove_decorators.py b/pyupgrade/_plugins/six_remove_decorators.py index 6998ac70..8d7f6178 100644 --- a/pyupgrade/_plugins/six_remove_decorators.py +++ b/pyupgrade/_plugins/six_remove_decorators.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/six_simple.py b/pyupgrade/_plugins/six_simple.py index d490d9e9..cbdf6897 100644 --- a/pyupgrade/_plugins/six_simple.py +++ b/pyupgrade/_plugins/six_simple.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/subprocess_run.py b/pyupgrade/_plugins/subprocess_run.py index 0452e48d..a4534c7d 100644 --- a/pyupgrade/_plugins/subprocess_run.py +++ b/pyupgrade/_plugins/subprocess_run.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/type_of_primitive.py b/pyupgrade/_plugins/type_of_primitive.py index 3dd834b3..b32a3146 100644 --- a/pyupgrade/_plugins/type_of_primitive.py +++ b/pyupgrade/_plugins/type_of_primitive.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/typing_classes.py b/pyupgrade/_plugins/typing_classes.py index b2f81f1c..92b7c925 100644 --- a/pyupgrade/_plugins/typing_classes.py +++ b/pyupgrade/_plugins/typing_classes.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/typing_pep563.py b/pyupgrade/_plugins/typing_pep563.py index 7b621209..a4fd368c 100644 --- a/pyupgrade/_plugins/typing_pep563.py +++ b/pyupgrade/_plugins/typing_pep563.py @@ -3,8 +3,8 @@ import ast import functools import sys -from typing import Iterable -from typing import Sequence +from collections.abc import Iterable +from collections.abc import Sequence from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/typing_pep585.py b/pyupgrade/_plugins/typing_pep585.py index e036c3f7..77dbd7e3 100644 --- a/pyupgrade/_plugins/typing_pep585.py +++ b/pyupgrade/_plugins/typing_pep585.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/typing_pep604.py b/pyupgrade/_plugins/typing_pep604.py index 2fc829e9..9b4039f2 100644 --- a/pyupgrade/_plugins/typing_pep604.py +++ b/pyupgrade/_plugins/typing_pep604.py @@ -3,7 +3,7 @@ import ast import functools import sys -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import NON_CODING_TOKENS from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/typing_pep646_unpack.py b/pyupgrade/_plugins/typing_pep646_unpack.py index 3493792e..9569d3c2 100644 --- a/pyupgrade/_plugins/typing_pep646_unpack.py +++ b/pyupgrade/_plugins/typing_pep646_unpack.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/typing_pep696_typevar_defaults.py b/pyupgrade/_plugins/typing_pep696_typevar_defaults.py index 3fe7c87e..97f00f2e 100644 --- a/pyupgrade/_plugins/typing_pep696_typevar_defaults.py +++ b/pyupgrade/_plugins/typing_pep696_typevar_defaults.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/typing_text.py b/pyupgrade/_plugins/typing_text.py index 031504b4..4e06dd36 100644 --- a/pyupgrade/_plugins/typing_text.py +++ b/pyupgrade/_plugins/typing_text.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/unittest_aliases.py b/pyupgrade/_plugins/unittest_aliases.py index 4b1a745d..9afe9552 100644 --- a/pyupgrade/_plugins/unittest_aliases.py +++ b/pyupgrade/_plugins/unittest_aliases.py @@ -2,7 +2,7 @@ import ast import functools -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset diff --git a/pyupgrade/_plugins/unpack_list_comprehension.py b/pyupgrade/_plugins/unpack_list_comprehension.py index ce072451..546a3dee 100644 --- a/pyupgrade/_plugins/unpack_list_comprehension.py +++ b/pyupgrade/_plugins/unpack_list_comprehension.py @@ -1,7 +1,7 @@ from __future__ import annotations import ast -from typing import Iterable +from collections.abc import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_plugins/versioned_branches.py b/pyupgrade/_plugins/versioned_branches.py index 05c776ac..1b6d3614 100644 --- a/pyupgrade/_plugins/versioned_branches.py +++ b/pyupgrade/_plugins/versioned_branches.py @@ -1,8 +1,8 @@ from __future__ import annotations import ast +from collections.abc import Iterable from typing import cast -from typing import Iterable from tokenize_rt import Offset from tokenize_rt import Token diff --git a/pyupgrade/_string_helpers.py b/pyupgrade/_string_helpers.py index 1c15655d..edea309c 100644 --- a/pyupgrade/_string_helpers.py +++ b/pyupgrade/_string_helpers.py @@ -4,11 +4,10 @@ import re import string from typing import Optional -from typing import Tuple NAMED_UNICODE_RE = re.compile(r'(?