Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions personal_python_ast_optimizer/parser/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def get_missing_tokens_iter(self) -> Iterator[tuple[str, str]]:
class TokenTypesConfig(_Config):
__slots__ = (
"simplify_named_tuples",
"skip_asserts",
"skip_dangling_expressions",
"skip_type_hints",
"skip_overload_functions",
Expand All @@ -116,11 +117,13 @@ def __init__(
*,
skip_dangling_expressions: bool = True,
skip_type_hints: TypeHintsToSkip = TypeHintsToSkip.ALL_BUT_CLASS_VARS,
skip_asserts: bool = False,
skip_overload_functions: bool = False,
simplify_named_tuples: bool = False,
) -> None:
self.skip_dangling_expressions: bool = skip_dangling_expressions
self.skip_type_hints: TypeHintsToSkip = skip_type_hints
self.skip_asserts: bool = skip_asserts
self.skip_overload_functions: bool = skip_overload_functions
self.simplify_named_tuples: bool = simplify_named_tuples

Expand Down
6 changes: 5 additions & 1 deletion personal_python_ast_optimizer/parser/skipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ def visit_ClassDef(self, node: ast.ClassDef) -> ast.AST | None:

if (
self.token_types_config.simplify_named_tuples
and isinstance(node, ast.ClassDef)
and self._is_simple_named_tuple(node)
):
self._simplified_named_tuple = True
Expand Down Expand Up @@ -525,6 +524,11 @@ def visit_Return(self, node: ast.Return) -> ast.AST:

return self.generic_visit(node)

def visit_Assert(self, node: ast.Assert) -> ast.AST | None:
return (
None if self.token_types_config.skip_asserts else self.generic_visit(node)
)

def visit_Pass(self, node: ast.Pass) -> None:
"""Always returns None. Caller responsible for ensuring empty bodies
are populated with a Pass node."""
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.2
6.1.0