Skip to content

Commit

Permalink
feat: added compilable flag
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Jun 25, 2024
1 parent f3dc482 commit 6009f2a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/pysource_minimize/_minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def minimize(
*,
progress_callback: Callable[[int, int], object] = lambda current, total: None,
retries: int = 1,
compilable=True,
) -> str:
"""
minimzes the source code
Expand All @@ -73,6 +74,7 @@ def minimize(
checker: a function which gets the source and returns `True` when the criteria is fullfilled.
progress_callback: function which is called everytime the source gets a bit smaller.
retries: the number of retries which sould be performed when the ast could be minimized (useful for non deterministic issues)
compilable: make shure that the minimized code can also be compiled and not just parsed.
returns the minimized source
"""
Expand All @@ -84,7 +86,8 @@ def source_checker(new_ast):
with warnings.catch_warnings():
source = unparse(new_ast)
warnings.simplefilter("ignore", SyntaxWarning)
compile(source, "<string>", "exec")
if compilable:
compile(source, "<string>", "exec")
except:
return False

Expand Down

0 comments on commit 6009f2a

Please sign in to comment.