Skip to content

Commit

Permalink
feat: support for 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Oct 3, 2023
1 parent ae36dbc commit 735e6ef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def mypy(session):
session.run("mypy", "pysource_minimize", "tests")


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"])
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"])
def test(session):
session.run_always("poetry", "install", "--with=dev", external=True)
session.env["COVERAGE_PROCESS_START"] = str(
Expand Down
17 changes: 10 additions & 7 deletions pysource_minimize/_minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,16 @@ def minimize_expr(self, node):
self.try_only_minimize(node, node.value, node.slice)

elif isinstance(node, ast.FormattedValue):
if (
isinstance(node.format_spec, ast.JoinedStr)
and len(node.format_spec.values) == 1
and self.try_only(node, node.format_spec.values[0])
):
self.minimize(node.format_spec.values[0])
return
if isinstance(node.format_spec, ast.JoinedStr):
# work around for https://github.com/python/cpython/issues/110309
spec = [
v
for v in node.format_spec.values
if not (isinstance(v, ast.Constant) and v.value == "")
]
if len(spec) == 1 and self.try_only(node, spec[0]):
self.minimize(spec[0])
return

self.try_none(node.format_spec)
self.minimize_expr(node.value)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_remove_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ def weight(node):
if sys.version_info >= (3, 8) and isinstance(node, ast.NamedExpr):
return 0

if isinstance(node, (ast.FormattedValue, ast.JoinedStr)):
if isinstance(node, ast.FormattedValue):
return 0
if isinstance(node, ast.JoinedStr):
# work around for https://github.com/python/cpython/issues/110309
return -(
sum(isinstance(n, ast.Constant) and n.value == "" for n in node.values)
)

if isinstance(node, ast.IfExp):
return -1
Expand Down

0 comments on commit 735e6ef

Please sign in to comment.