Skip to content

Commit

Permalink
Don't repeatedly unparse node.test
Browse files Browse the repository at this point in the history
.. it's not needed.
  • Loading branch information
jepler committed Jun 17, 2024
1 parent 4a98e1a commit 2d263bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions circuitpython_build_tools/munge.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ def process_statement(node):
break
return
elif isinstance(node, ast.If):
node_test = ast.unparse(node.test)
# return the statements in the 'if' branch of 'if sys.implementation...: ...'
if ast.unparse(node.test) == sys_implementation_is_circuitpython:
if node_test == sys_implementation_is_circuitpython:
replace(node.lineno, 'if 1:')
# return the statements in the 'else' branch of 'if sys.implementation...: ...'
if ast.unparse(node.test) == sys_implementation_not_circuitpython or ast.unparse(node.test) == sys_implementation_not_circuitpython2:
elif node_test == sys_implementation_not_circuitpython or node_test == sys_implementation_not_circuitpython2:
replace(node.lineno, 'if 0:')
# return the statements in the else branch of 'if TYPE_CHECKING: ...'
elif ast.unparse(node.test) == 'TYPE_CHECKING':
elif node_test == 'TYPE_CHECKING':
replace(node.lineno, 'if 0:')
elif isinstance(node, ast.Assign) and isinstance(node.targets[0], ast.Name) and node.targets[0].id == '__version__':
replace(node.lineno, f"__version__ = \"{version_str}\"")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_munge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def test_munge(test_path):
result_content = munge(test_path, "1.2.3")
result_path.write_text(result_content, encoding="utf-8")

expected = test_path.with_suffix(".exp")
expected_content = expected.read_text(encoding="utf-8")
expected_path = test_path.with_suffix(".exp")
expected_content = expected_path.read_text(encoding="utf-8")

assert result == expected
assert result_content == expected_content

result_path.unlink()

0 comments on commit 2d263bb

Please sign in to comment.