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

remove support for python 3.8 #947

Merged
merged 1 commit into from
Jun 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
main-windows:
uses: asottile/workflows/.github/workflows/[email protected]
with:
env: '["py38"]'
env: '["py39"]'
os: windows-latest
main-linux:
uses: asottile/workflows/.github/workflows/[email protected]
with:
env: '["py38", "py39", "py310", "py311", "py312"]'
env: '["py39", "py310", "py311", "py312"]'
os: ubuntu-latest
17 changes: 5 additions & 12 deletions pyupgrade/_plugins/typing_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ast
import functools
import sys
from typing import Iterable

from tokenize_rt import Offset
Expand All @@ -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
Expand Down
11 changes: 2 additions & 9 deletions pyupgrade/_plugins/typing_pep563.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 5 additions & 19 deletions pyupgrade/_plugins/typing_pep604.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyupgrade/_plugins/typing_pep646_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading