Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codegen visitor functions #23

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions libcst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
AugAssign,
BaseCompoundStatement,
BaseSmallStatement,
BaseStatement,
BaseSuite,
Break,
ClassDef,
Expand Down Expand Up @@ -345,6 +346,7 @@
"AugAssign",
"BaseCompoundStatement",
"BaseSmallStatement",
"BaseStatement",
"BaseSuite",
"Break",
"ClassDef",
Expand Down
2 changes: 1 addition & 1 deletion libcst/_batched_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
cast,
)

from libcst._typed_visitor_base import CSTTypedVisitorFunctions
from libcst._typed_visitor import CSTTypedVisitorFunctions
from libcst._visitors import CSTNodeT, CSTVisitor
from libcst.metadata.dependent import MetadataDependent

Expand Down
20 changes: 13 additions & 7 deletions libcst/_nodes/_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ class BaseSuite(CSTNode, ABC):
-- https://docs.python.org/3/reference/compound_stmts.html
"""

body: Union[
Sequence[Union["SimpleStatementLine", "BaseCompoundStatement"]],
Sequence["BaseSmallStatement"],
]
body: Union[Sequence["BaseStatement"], Sequence["BaseSmallStatement"]]


class BaseStatement(CSTNode, ABC):
DragonMinded marked this conversation as resolved.
Show resolved Hide resolved
"""
A class that exists to allow for typing to specify that any statement is allowed
in a particular location.
"""

pass


class BaseSmallStatement(CSTNode, ABC):
Expand Down Expand Up @@ -379,7 +385,7 @@ def _codegen_impl(self, state: CodegenState) -> None:

@add_slots
@dataclass(frozen=True)
class SimpleStatementLine(_BaseSimpleStatement):
class SimpleStatementLine(_BaseSimpleStatement, BaseStatement):
"""
A simple statement that's part of an IndentedBlock or Module. A simple statement is
a series of small statements joined together by semicolons.
Expand Down Expand Up @@ -509,7 +515,7 @@ def _codegen_impl(self, state: CodegenState) -> None:
self.body._codegen(state)


class BaseCompoundStatement(CSTNode, ABC):
class BaseCompoundStatement(BaseStatement, ABC):
"""
Encapsulates a compound statement, like ``if True: pass`` or ``while True: pass``.
This exists to simplify type definitions and isinstance checks.
Expand Down Expand Up @@ -619,7 +625,7 @@ class IndentedBlock(BaseSuite):
"""

#: Sequence of statements belonging to this indented block.
body: Sequence[Union[SimpleStatementLine, BaseCompoundStatement]]
body: Sequence[BaseStatement]

#: Any optional trailing comment and the final ``NEWLINE`` at the end of the line.
header: TrailingWhitespace = TrailingWhitespace()
Expand Down