AstNode

class AstNode

The basic type of all AST nodes.

Children
Members defined in AstNode (9 members)

cst_node

R

The source CST node of self if one exists.

document

R

The document that owns this node.

owned_elements

R

Returns a view into all elements directly owned by this Element.

parent

R

The parent node of self.

__hash__

Identity based hash of this node.

__str__

cast

  1. cast(self, *type: type[TNode]) -> TNode

isinstance

Chainable equivalent to isintance(self, type)

try_cast

Checked cast to type.

Attributes

property cst_node: syside.CstNode | None

The source CST node of self if one exists.

This is only available on nodes parsed from text sources, and only on nodes that have not been created implicitly to satisfy some constraints.

property document: syside.Document

The document that owns this node.

In Syside, all AST nodes are attached to their owning documents, this improves performance and ergonomics in certain places at the cost of not being able to move nodes between documents.

Note that this assumes that the returned document and all of its transitive dependencies will not be accessed from other threads, e.g. by acquiring locks to all dependent (downstream) documents.

property owned_elements: syside.LazyIterator[syside.Element]

Returns a view into all elements directly owned by this Element.

property parent: syside.Element | None

The parent node of self.

Methods

__hash__() int

Identity based hash of this node.

This is guaranteed to be unique or nearly unique globally (due to bit mixing). However, it is not stable across Python invocations, and erased elements may be reused internally with the same hash.

__str__() str
cast(type: tuple[syside.AstNode.cast.type[syside.TNode], ...]) syside.TNode
cast(*type: type[syside.TNode]) syside.TNode

Checked cast to type.

Similar to typing.cast(type, self) except this raises TypeError if the cast fails.

isinstance(type: syside.AstNode.isinstance.type[syside.TNode]) TypeGuard[syside.TNode]

Chainable equivalent to isintance(self, type)

isinstance(type: tuple[syside.AstNode.isinstance.type[syside.TNode], ...]) TypeGuard[syside.TNode]
try_cast(type: tuple[syside.AstNode.try_cast.type[syside.TNode], ...]) syside.TNode | None

Checked cast to type.

Similar to typing.cast(type, self) except this returns None if the cast fails.

try_cast(*type: type[syside.TNode]) syside.TNode | None
Used in