Skip to content

Commit f8af4ed

Browse files
authored
Merge pull request #281 from asottile/drop-py38
drop support for python 3.8
2 parents d0cd933 + 1de7243 commit f8af4ed

File tree

14 files changed

+35
-47
lines changed

14 files changed

+35
-47
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
main-windows:
1111
uses: asottile/workflows/.github/workflows/[email protected]
1212
with:
13-
env: '["py38"]'
13+
env: '["py39"]'
1414
os: windows-latest
1515
main-linux:
1616
uses: asottile/workflows/.github/workflows/[email protected]
1717
with:
18-
env: '["py38", "py39", "py310", "py311", "py312"]'
18+
env: '["py39", "py310", "py311", "py312"]'
1919
os: ubuntu-latest

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
rev: v3.13.0
1818
hooks:
1919
- id: reorder-python-imports
20-
args: [--py38-plus, --add-import, 'from __future__ import annotations']
20+
args: [--py39-plus, --add-import, 'from __future__ import annotations']
2121
- repo: https://github.com/asottile/add-trailing-comma
2222
rev: v3.1.0
2323
hooks:
@@ -26,7 +26,7 @@ repos:
2626
rev: v3.16.0
2727
hooks:
2828
- id: pyupgrade
29-
args: [--py38-plus]
29+
args: [--py39-plus]
3030
- repo: https://github.com/hhatto/autopep8
3131
rev: v2.3.1
3232
hooks:

add_trailing_comma/_ast_helpers.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,4 @@ def ast_parse(contents_text: str) -> ast.Module:
1313

1414

1515
def ast_to_offset(node: ast.AST) -> Offset:
16-
candidates = [node]
17-
while candidates:
18-
candidate = candidates.pop()
19-
if hasattr(candidate, 'lineno'):
20-
return Offset(candidate.lineno, candidate.col_offset)
21-
elif hasattr(candidate, '_fields'): # pragma: <3.9 cover
22-
for field in reversed(candidate._fields):
23-
candidates.append(getattr(candidate, field))
24-
else:
25-
raise AssertionError(node)
16+
return Offset(node.lineno, node.col_offset)

add_trailing_comma/_data.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import ast
44
import collections
55
import pkgutil
6+
from collections.abc import Iterable
67
from typing import Callable
7-
from typing import Iterable
8-
from typing import List
98
from typing import NamedTuple
109
from typing import Protocol
11-
from typing import Tuple
1210
from typing import TypeVar
1311

1412
from tokenize_rt import Offset
@@ -22,8 +20,8 @@ class State(NamedTuple):
2220

2321

2422
AST_T = TypeVar('AST_T', bound=ast.AST)
25-
TokenFunc = Callable[[int, List[Token]], None]
26-
ASTFunc = Callable[[State, AST_T], Iterable[Tuple[Offset, TokenFunc]]]
23+
TokenFunc = Callable[[int, list[Token]], None]
24+
ASTFunc = Callable[[State, AST_T], Iterable[tuple[Offset, TokenFunc]]]
2725

2826
FUNCS = collections.defaultdict(list)
2927

add_trailing_comma/_main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import argparse
44
import sys
5-
from typing import Iterable
6-
from typing import Sequence
5+
from collections.abc import Iterable
6+
from collections.abc import Sequence
77

88
from tokenize_rt import src_to_tokens
99
from tokenize_rt import Token

add_trailing_comma/_plugins/_with.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from __future__ import annotations
22

33
import ast
4-
import sys
5-
from typing import Iterable
4+
from collections.abc import Iterable
65

76
from tokenize_rt import Offset
87
from tokenize_rt import Token
@@ -15,20 +14,20 @@
1514
from add_trailing_comma._token_helpers import fix_brace
1615

1716

18-
if sys.version_info >= (3, 9): # pragma: >=3.9 cover
19-
def _fix_with(i: int, tokens: list[Token]) -> None:
17+
def _fix_with(i: int, tokens: list[Token]) -> None:
18+
i += 1
19+
if tokens[i].name == 'UNIMPORTANT_WS':
2020
i += 1
21-
if tokens[i].name == 'UNIMPORTANT_WS':
22-
i += 1
23-
if tokens[i].src == '(':
24-
fix = find_simple(i, tokens)
25-
# only fix if outer parens are for the with items (next is ':')
26-
if fix is not None and tokens[fix.braces[-1] + 1].src == ':':
27-
fix_brace(tokens, fix, add_comma=True, remove_comma=True)
21+
if tokens[i].src == '(':
22+
fix = find_simple(i, tokens)
23+
# only fix if outer parens are for the with items (next is ':')
24+
if fix is not None and tokens[fix.braces[-1] + 1].src == ':':
25+
fix_brace(tokens, fix, add_comma=True, remove_comma=True)
2826

29-
@register(ast.With)
30-
def visit_With(
31-
state: State,
32-
node: ast.With,
33-
) -> Iterable[tuple[Offset, TokenFunc]]:
34-
yield ast_to_offset(node), _fix_with
27+
28+
@register(ast.With)
29+
def visit_With(
30+
state: State,
31+
node: ast.With,
32+
) -> Iterable[tuple[Offset, TokenFunc]]:
33+
yield ast_to_offset(node), _fix_with

add_trailing_comma/_plugins/calls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import ast
44
import functools
5-
from typing import Iterable
5+
from collections.abc import Iterable
66

77
from tokenize_rt import Offset
88
from tokenize_rt import Token

add_trailing_comma/_plugins/classes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import ast
44
import functools
5-
from typing import Iterable
5+
from collections.abc import Iterable
66

77
from tokenize_rt import Offset
88
from tokenize_rt import Token

add_trailing_comma/_plugins/functions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import ast
44
import functools
5-
from typing import Iterable
5+
from collections.abc import Iterable
66

77
from tokenize_rt import Offset
88
from tokenize_rt import Token

add_trailing_comma/_plugins/imports.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import ast
4-
from typing import Iterable
4+
from collections.abc import Iterable
55

66
from tokenize_rt import Offset
77
from tokenize_rt import Token

add_trailing_comma/_plugins/literals.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import ast
44
import functools
5-
from typing import Iterable
5+
from collections.abc import Iterable
66

77
from tokenize_rt import NON_CODING_TOKENS
88
from tokenize_rt import Offset
@@ -91,7 +91,7 @@ def _fix_tuple_py38(
9191
tokens: list[Token],
9292
*,
9393
one_el_tuple: bool,
94-
) -> None: # pragma: >=3.8 cover
94+
) -> None:
9595
fix = find_simple(i, tokens)
9696

9797
# for tuples we *must* find a comma, otherwise it is not a tuple

add_trailing_comma/_plugins/match.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import ast
44
import functools
55
import sys
6-
from typing import Iterable
6+
from collections.abc import Iterable
77

88
from tokenize_rt import Offset
99
from tokenize_rt import Token

add_trailing_comma/_plugins/pep695.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import ast
44
import sys
5-
from typing import Iterable
5+
from collections.abc import Iterable
66

77
from tokenize_rt import Offset
88
from tokenize_rt import Token

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ classifiers =
2020
packages = find:
2121
install_requires =
2222
tokenize-rt>=3.0.1
23-
python_requires = >=3.8
23+
python_requires = >=3.9
2424

2525
[options.packages.find]
2626
exclude =

0 commit comments

Comments
 (0)