Skip to content

Commit

Permalink
Merge pull request #835 from asottile/py312
Browse files Browse the repository at this point in the history
remove dependence on deprecated ast things (again)
  • Loading branch information
asottile committed Jun 10, 2023
2 parents ccc391b + 963ecb9 commit c994a92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
main-linux:
uses: asottile/workflows/.github/workflows/tox.yml@v1.0.0
with:
env: '["py38", "py39", "py310"]'
env: '["py38", "py39", "py310", "py311", "py312"]'
os: ubuntu-latest
4 changes: 2 additions & 2 deletions pyupgrade/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _fix_format_literal(tokens: list[Token], end: int) -> None:
for i in parts:
# f'foo {0}'.format(...) would get turned into a SyntaxError
prefix, _ = parse_string_literal(tokens[i].src)
if 'f' in prefix.lower():
if 'f' in prefix.lower(): # pragma: <3.12 cover
return

try:
Expand Down Expand Up @@ -244,7 +244,7 @@ def _fix_encode_to_binary(tokens: list[Token], i: int) -> None:
):
victims = slice(i - 1, i + 4)
prefix, rest = parse_string_literal(tokens[i + 2].src)
if 'f' in prefix.lower():
if 'f' in prefix.lower(): # pragma: <3.12 cover
return
encoding = ast.literal_eval(prefix + rest)
if is_codec(encoding, 'ascii') or is_codec(encoding, 'utf-8'):
Expand Down
7 changes: 5 additions & 2 deletions pyupgrade/_plugins/native_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def visit_Call(
isinstance(node.func, ast.Name) and node.func.id == 'bytes' and
not node.keywords and not has_starargs(node) and
(
len(node.args) == 0 or
(len(node.args) == 1 and isinstance(node.args[0], ast.Bytes))
len(node.args) == 0 or (
len(node.args) == 1 and
isinstance(node.args[0], ast.Constant) and
isinstance(node.args[0].value, bytes)
)
)
):
func = functools.partial(_fix_literal, empty="b''")
Expand Down
5 changes: 1 addition & 4 deletions pyupgrade/_plugins/typing_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ def visit_Assign(
(
len(node.value.keywords) == 1 and
node.value.keywords[0].arg == 'total' and
isinstance(
node.value.keywords[0].value,
(ast.Constant, ast.NameConstant),
)
isinstance(node.value.keywords[0].value, ast.Constant)
)
) and
isinstance(node.value.args[1], ast.Dict) and
Expand Down

0 comments on commit c994a92

Please sign in to comment.