From c25513c7b2a4b7315161b7c88f1d80a038606bfa Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 8 Jun 2024 15:32:31 -0400 Subject: [PATCH] remove support for python 3.8 --- .github/workflows/main.yml | 4 ++-- pyupgrade/_plugins/typing_classes.py | 17 +++++---------- pyupgrade/_plugins/typing_pep563.py | 11 ++-------- pyupgrade/_plugins/typing_pep604.py | 24 +++++----------------- pyupgrade/_plugins/typing_pep646_unpack.py | 2 +- setup.cfg | 2 +- 6 files changed, 16 insertions(+), 44 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3b225b73..804dc78b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,10 +10,10 @@ jobs: main-windows: uses: asottile/workflows/.github/workflows/tox.yml@v1.6.0 with: - env: '["py38"]' + env: '["py39"]' os: windows-latest main-linux: uses: asottile/workflows/.github/workflows/tox.yml@v1.6.0 with: - env: '["py38", "py39", "py310", "py311", "py312"]' + env: '["py39", "py310", "py311", "py312"]' os: ubuntu-latest diff --git a/pyupgrade/_plugins/typing_classes.py b/pyupgrade/_plugins/typing_classes.py index 26de3b1b..b2f81f1c 100644 --- a/pyupgrade/_plugins/typing_classes.py +++ b/pyupgrade/_plugins/typing_classes.py @@ -2,7 +2,6 @@ import ast import functools -import sys from typing import Iterable from tokenize_rt import Offset @@ -24,19 +23,13 @@ def _unparse(node: ast.expr) -> str: elif isinstance(node, ast.Attribute): return ''.join((_unparse(node.value), '.', node.attr)) elif isinstance(node, ast.Subscript): - if sys.version_info >= (3, 9): # pragma: >=3.9 cover - node_slice: ast.expr = node.slice - elif isinstance(node.slice, ast.Index): # pragma: <3.9 cover - node_slice = node.slice.value - else: - raise AssertionError(f'expected Slice: {ast.dump(node)}') - if isinstance(node_slice, ast.Tuple): - if len(node_slice.elts) == 1: - slice_s = f'{_unparse(node_slice.elts[0])},' + if isinstance(node.slice, ast.Tuple): + if len(node.slice.elts) == 1: + slice_s = f'{_unparse(node.slice.elts[0])},' else: - slice_s = ', '.join(_unparse(elt) for elt in node_slice.elts) + slice_s = ', '.join(_unparse(elt) for elt in node.slice.elts) else: - slice_s = _unparse(node_slice) + slice_s = _unparse(node.slice) return f'{_unparse(node.value)}[{slice_s}]' elif ( isinstance(node, ast.Constant) and diff --git a/pyupgrade/_plugins/typing_pep563.py b/pyupgrade/_plugins/typing_pep563.py index 4bf40c39..7b621209 100644 --- a/pyupgrade/_plugins/typing_pep563.py +++ b/pyupgrade/_plugins/typing_pep563.py @@ -90,15 +90,8 @@ def _process_call(node: ast.Call) -> Iterable[ast.AST]: def _process_subscript(node: ast.Subscript) -> Iterable[ast.AST]: name = _get_name(node.value) if name == 'Annotated': - if sys.version_info >= (3, 9): # pragma: >=3.9 cover - node_slice = node.slice - elif isinstance(node.slice, ast.Index): # pragma: <3.9 cover - node_slice: ast.AST = node.slice.value - else: # pragma: <3.9 cover - node_slice = node.slice - - if isinstance(node_slice, ast.Tuple) and node_slice.elts: - yield node_slice.elts[0] + if isinstance(node.slice, ast.Tuple) and node.slice.elts: + yield node.slice.elts[0] elif name != 'Literal': yield node.slice diff --git a/pyupgrade/_plugins/typing_pep604.py b/pyupgrade/_plugins/typing_pep604.py index c7b53bc0..2fc829e9 100644 --- a/pyupgrade/_plugins/typing_pep604.py +++ b/pyupgrade/_plugins/typing_pep604.py @@ -153,14 +153,7 @@ def visit_Subscript( # don't rewrite forward annotations (unless we know they will be dequoted) if 'annotations' not in state.from_imports['__future__']: - if ( - (sys.version_info >= (3, 9) and _any_arg_is_str(node.slice)) or - ( - sys.version_info < (3, 9) and - isinstance(node.slice, ast.Index) and - _any_arg_is_str(node.slice.value) - ) - ): + if _any_arg_is_str(node.slice): return if is_name_attr( @@ -171,19 +164,12 @@ def visit_Subscript( ): yield ast_to_offset(node), _fix_optional elif is_name_attr(node.value, state.from_imports, ('typing',), ('Union',)): - if sys.version_info >= (3, 9): # pragma: >=3.9 cover - node_slice = node.slice - elif isinstance(node.slice, ast.Index): # pragma: <3.9 cover - node_slice: ast.AST = node.slice.value - else: # pragma: <3.9 cover - node_slice = node.slice # unexpected slice type - - if isinstance(node_slice, ast.Slice): # not a valid annotation + if isinstance(node.slice, ast.Slice): # not a valid annotation return - if isinstance(node_slice, ast.Tuple): - if node_slice.elts: - arg_count = len(node_slice.elts) + if isinstance(node.slice, ast.Tuple): + if node.slice.elts: + arg_count = len(node.slice.elts) else: return # empty Union else: diff --git a/pyupgrade/_plugins/typing_pep646_unpack.py b/pyupgrade/_plugins/typing_pep646_unpack.py index 4cee0d23..3493792e 100644 --- a/pyupgrade/_plugins/typing_pep646_unpack.py +++ b/pyupgrade/_plugins/typing_pep646_unpack.py @@ -35,7 +35,7 @@ def visit_Subscript( return if is_name_attr(node.value, state.from_imports, ('typing',), ('Unpack',)): - if isinstance(parent, (ast.Subscript, ast.Index)): + if isinstance(parent, ast.Subscript): yield ast_to_offset(node.value), _replace_unpack_with_star diff --git a/setup.cfg b/setup.cfg index 6d2bc052..c25d559d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,7 +20,7 @@ classifiers = packages = find: install_requires = tokenize-rt>=5.2.0 -python_requires = >=3.8.1 +python_requires = >=3.9 [options.packages.find] exclude =