CSTNode and its subclasses cover Python's full grammar in a whitespace-sensitive fashion, forming LibCST's concrete syntax tree.
Many of these nodes are designed to behave similarly to Python's abstract syntax tree.
The base node type which all other nodes derive from.
.. autoclass:: libcst.CSTNode
A node that represents an entire python module.
.. autoclass:: libcst.Module
An expression is anything that represents a value (e.g. it could be returned from a function). All expressions subclass from :class:`~libcst.BaseExpression`.
Expression can be parsed with :func:`~libcst.parse_expression` or as part of a statement or module using :func:`~libcst.parse_statement` or :func:`~libcst.parse_module`.
.. autoclass:: libcst.BaseExpression
.. autoclass:: libcst.Name
.. autoclass:: libcst.Attribute
Operation and Comparison nodes combine one or more expressions with an operator.
.. autoclass:: libcst.UnaryOperation
.. autoclass:: libcst.BinaryOperation
.. autoclass:: libcst.BooleanOperation
.. autoclass:: libcst.Comparison
.. autoclass:: libcst.ComparisonTarget
.. autoclass:: libcst.Asynchronous
.. autoclass:: libcst.Await
.. autoclass:: libcst.Yield
.. autoclass:: libcst.From
.. autoclass:: libcst.IfExp
.. autoclass:: libcst.Lambda
.. autoclass:: libcst.Call
.. autoclass:: libcst.Arg
.. autoclass:: libcst.Ellipsis
.. autoclass:: libcst.BaseNumber
.. autoclass:: libcst.Integer
.. autoclass:: libcst.Float
.. autoclass:: libcst.Imaginary
.. autoclass:: libcst.BaseString
.. autoclass:: libcst.SimpleString
.. autoclass:: libcst.ConcatenatedString
.. autoclass:: libcst.FormattedString
.. autoclass:: libcst.BaseFormattedStringContent
.. autoclass:: libcst.FormattedStringText
.. autoclass:: libcst.FormattedStringExpression
.. autoclass:: libcst.Tuple
.. autoclass:: libcst.BaseList
.. autoclass:: libcst.List
.. autoclass:: libcst.BaseSet
.. autoclass:: libcst.Set
.. autoclass:: libcst.BaseElement
.. autoclass:: libcst.Element
.. autoclass:: libcst.StarredElement
.. autoclass:: libcst.BaseDict
.. autoclass:: libcst.Dict
.. autoclass:: libcst.BaseDictElement
.. autoclass:: libcst.DictElement
.. autoclass:: libcst.StarredDictElement
.. autoclass:: libcst.BaseComp
.. autoclass:: libcst.BaseSimpleComp
.. autoclass:: libcst.GeneratorExp
.. autoclass:: libcst.ListComp
.. autoclass:: libcst.SetComp
.. autoclass:: libcst.DictComp
.. autoclass:: libcst.CompFor
.. autoclass:: libcst.CompIf
.. autoclass:: libcst.Subscript
.. autoclass:: libcst.BaseSlice
.. autoclass:: libcst.Index
.. autoclass:: libcst.Slice
.. autoclass:: libcst.SubscriptElement
.. autoclass:: libcst.LeftParen
.. autoclass:: libcst.RightParen
.. autoclass:: libcst.LeftSquareBracket
.. autoclass:: libcst.RightSquareBracket
.. autoclass:: libcst.LeftCurlyBrace
.. autoclass:: libcst.RightCurlyBrace
Statements represent a "line of code" or a control structure with other lines of code, such as an :class:`~libcst.If` block.
All statements subclass from :class:`~libcst.BaseSmallStatement` or :class:`~libcst.BaseCompoundStatement`.
Statements can be parsed with :func:`~libcst.parse_statement` or as part of a module using :func:`~libcst.parse_module`.
Statements which at most have expressions as child attributes.
.. autoclass:: libcst.BaseSmallStatement
.. autoclass:: libcst.AnnAssign
.. autoclass:: libcst.Assert
.. autoclass:: libcst.Assign
.. autoclass:: libcst.AugAssign
.. autoclass:: libcst.Break
.. autoclass:: libcst.Continue
.. autoclass:: libcst.Del
.. autoclass:: libcst.Expr
.. autoclass:: libcst.Global
.. autoclass:: libcst.Import
.. autoclass:: libcst.ImportFrom
.. autoclass:: libcst.Nonlocal
.. autoclass:: libcst.Pass
.. autoclass:: libcst.Raise
.. autoclass:: libcst.Return
Statements that have one or more statement blocks as a child attribute.
.. autoclass:: libcst.BaseCompoundStatement
.. autoclass:: libcst.ClassDef
.. autoclass:: libcst.For
.. autoclass:: libcst.FunctionDef
.. autoclass:: libcst.If
.. autoclass:: libcst.Try
.. autoclass:: libcst.While
.. autoclass:: libcst.With
Nodes that are used by various statements to represent some syntax, but are not statements on their own and cannot be used outside of the statements they belong with.
.. autoclass:: libcst.Annotation
.. autoclass:: libcst.AsName
.. autoclass:: libcst.AssignTarget
.. autoclass:: libcst.BaseAssignTargetExpression
.. autoclass:: libcst.BaseDelTargetExpression
.. autoclass:: libcst.Decorator
.. autoclass:: libcst.Else
.. autoclass:: libcst.ExceptHandler
.. autoclass:: libcst.Finally
.. autoclass:: libcst.ImportAlias
.. autoclass:: libcst.NameItem
.. autoclass:: libcst.Parameters
.. autoclass:: libcst.Param
.. autoclass:: libcst.ParamSlash
.. autoclass:: libcst.ParamStar
.. autoclass:: libcst.WithItem
Nodes that represent some group of statements.
.. autoclass:: libcst.BaseSuite
.. autoclass:: libcst.SimpleStatementLine
.. autoclass:: libcst.SimpleStatementSuite
.. autoclass:: libcst.IndentedBlock
Nodes that are used to signify an operation to be performed on a variable or value.
Nodes that are used with :class:`~libcst.UnaryOperation` to perform some unary operation.
.. autoclass:: libcst.Plus
In addition, :class:`~libcst.BaseUnaryOp` is defined purely for typing and isinstance checks.
Nodes that are used with :class:`~libcst.BooleanOperation` to perform some boolean operation.
.. autoclass:: libcst.Or
In addition, :class:`~libcst.BaseBooleanOp` is defined purely for typing and isinstance checks.
Nodes that are used with :class:`~libcst.BinaryOperation` to perform some binary operation.
.. autoclass:: libcst.Subtract
In addition, :class:`~libcst.BaseBinaryOp` is defined purely for typing and isinstance checks.
Nodes that are used with :class:`~libcst.Comparison` to perform some comparison operation.
.. autoclass:: libcst.LessThanEqual
.. autoclass:: libcst.NotEqual
.. autoclass:: libcst.NotIn
In addition, :class:`~libcst.BaseCompOp` is defined purely for typing and isinstance checks.
Nodes that are used with :class:`~libcst.AugAssign` to perform some agumented assignment.
.. autoclass:: libcst.SubtractAssign
In addition, :class:`~libcst.BaseAugOp` is defined purely for typing and isinstance checks.
Miscelaneous nodes that are purely syntactic trivia. While python requires these nodes in order to parse a module, statement or expression they do not carry any meaning on their own.
.. autoclass:: libcst.AssignEqual
.. autoclass:: libcst.Colon
.. autoclass:: libcst.Comma
.. autoclass:: libcst.Dot
.. autoclass:: libcst.ImportStar
.. autoclass:: libcst.Semicolon
Nodes that encapsulate pure whitespace.
.. autoclass:: libcst.Comment
.. autoclass:: libcst.EmptyLine
.. autoclass:: libcst.Newline
.. autoclass:: libcst.ParenthesizedWhitespace
.. autoclass:: libcst.SimpleWhitespace
.. autoclass:: libcst.TrailingWhitespace
.. autoclass:: libcst.BaseParenthesizableWhitespace
.. autoclass:: libcst.MaybeSentinel