File: nodes.rst

package info (click to toggle)
python-libcst 1.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,240 kB
  • sloc: python: 78,096; makefile: 15; sh: 2
file content (401 lines) | stat: -rw-r--r-- 9,632 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
.. _libcst-nodes:

Nodes
=====

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 <https://greentreesnakes.readthedocs.io/en/latest/nodes.html>`_.

CSTNode
-------

The base node type which all other nodes derive from.

.. autoclass:: libcst.CSTNode

Module
------

A node that represents an entire python module.

.. autoclass:: libcst.Module

Expressions
-----------

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

Names and Object Attributes
^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: libcst.Name
.. autoclass:: libcst.Attribute

Operations and Comparisons
^^^^^^^^^^^^^^^^^^^^^^^^^^

Operation and Comparison nodes combine one or more expressions with an
operator_.

.. _operator: Operators_

.. autoclass:: libcst.UnaryOperation
.. autoclass:: libcst.BinaryOperation
.. autoclass:: libcst.BooleanOperation
.. autoclass:: libcst.Comparison
.. autoclass:: libcst.ComparisonTarget

Control Flow
^^^^^^^^^^^^

.. autoclass:: libcst.Asynchronous
.. autoclass:: libcst.Await
.. autoclass:: libcst.Yield
.. autoclass:: libcst.From
.. autoclass:: libcst.IfExp

Lambdas and Function Calls
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: libcst.Lambda
.. autoclass:: libcst.Call
.. autoclass:: libcst.Arg

Literal Values
^^^^^^^^^^^^^^

.. autoclass:: libcst.Ellipsis

Numbers
'''''''

.. autoclass:: libcst.BaseNumber
.. autoclass:: libcst.Integer
.. autoclass:: libcst.Float
.. autoclass:: libcst.Imaginary

Strings
'''''''

.. autoclass:: libcst.BaseString
.. autoclass:: libcst.SimpleString
.. autoclass:: libcst.ConcatenatedString

Formatted Strings (f-strings)
'''''''''''''''''''''''''''''

.. autoclass:: libcst.FormattedString
.. autoclass:: libcst.BaseFormattedStringContent
.. autoclass:: libcst.FormattedStringText
.. autoclass:: libcst.FormattedStringExpression

Collections
^^^^^^^^^^^

Simple Collections
''''''''''''''''''

.. autoclass:: libcst.Tuple

.. autoclass:: libcst.BaseList
.. autoclass:: libcst.List

.. autoclass:: libcst.BaseSet
.. autoclass:: libcst.Set

Simple Collection Elements
''''''''''''''''''''''''''

.. autoclass:: libcst.BaseElement
.. autoclass:: libcst.Element
.. autoclass:: libcst.StarredElement

Dictionaries
''''''''''''

.. autoclass:: libcst.BaseDict
.. autoclass:: libcst.Dict

Dictionary Elements
'''''''''''''''''''

.. autoclass:: libcst.BaseDictElement
.. autoclass:: libcst.DictElement
.. autoclass:: libcst.StarredDictElement

Comprehensions
^^^^^^^^^^^^^^

.. autoclass:: libcst.BaseComp
.. autoclass:: libcst.BaseSimpleComp

.. autoclass:: libcst.GeneratorExp
.. autoclass:: libcst.ListComp
.. autoclass:: libcst.SetComp
.. autoclass:: libcst.DictComp

.. autoclass:: libcst.CompFor
.. autoclass:: libcst.CompIf

Subscripts and Slices
^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: libcst.Subscript
.. autoclass:: libcst.BaseSlice
.. autoclass:: libcst.Index
.. autoclass:: libcst.Slice
.. autoclass:: libcst.SubscriptElement

Parenthesis, Brackets, and Braces
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: libcst.LeftParen
.. autoclass:: libcst.RightParen

.. autoclass:: libcst.LeftSquareBracket
.. autoclass:: libcst.RightSquareBracket

.. autoclass:: libcst.LeftCurlyBrace
.. autoclass:: libcst.RightCurlyBrace

Statements
----------

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`.

Simple Statements
^^^^^^^^^^^^^^^^^

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


Compound Statements
^^^^^^^^^^^^^^^^^^^

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

Helper Nodes
^^^^^^^^^^^^

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.

.. Annotation is in the expression module for import-order reasons, it's
   most-often used a a helper for statements (e.g. functions)
.. 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

.. Params are in the expression module for import-order reasons, but it makes
   sense to group these closer to FunctionDef than with Lambda.
.. autoclass:: libcst.Parameters
.. autoclass:: libcst.Param
.. autoclass:: libcst.ParamSlash
.. autoclass:: libcst.ParamStar

.. autoclass:: libcst.WithItem

Statement Blocks
^^^^^^^^^^^^^^^^

Nodes that represent some group of statements.

.. autoclass:: libcst.BaseSuite
.. autoclass:: libcst.SimpleStatementLine
.. autoclass:: libcst.SimpleStatementSuite
.. autoclass:: libcst.IndentedBlock

Operators
---------

Nodes that are used to signify an operation to be performed on a variable
or value.

Unary Operators
^^^^^^^^^^^^^^^

Nodes that are used with :class:`~libcst.UnaryOperation` to perform some unary
operation.

.. class:: libcst.BitInvert
.. class:: libcst.Minus
.. class:: libcst.Not
.. autoclass:: libcst.Plus

In addition, :class:`~libcst.BaseUnaryOp` is defined purely for typing and isinstance
checks.

.. class:: libcst.BaseUnaryOp

Boolean Operators
^^^^^^^^^^^^^^^^^

Nodes that are used with :class:`~libcst.BooleanOperation` to perform some boolean
operation.

.. class:: libcst.And
.. autoclass:: libcst.Or

In addition, :class:`~libcst.BaseBooleanOp` is defined purely for typing and isinstance
checks.

.. class:: libcst.BaseBooleanOp

Binary Operators
^^^^^^^^^^^^^^^^

Nodes that are used with :class:`~libcst.BinaryOperation` to perform some binary
operation.

.. class:: libcst.Add
.. class:: libcst.BitAnd
.. class:: libcst.BitOr
.. class:: libcst.BitXor
.. class:: libcst.Divide
.. class:: libcst.FloorDivide
.. class:: libcst.LeftShift
.. class:: libcst.MatrixMultiply
.. class:: libcst.Modulo
.. class:: libcst.Multiply
.. class:: libcst.Power
.. class:: libcst.RightShift
.. autoclass:: libcst.Subtract

In addition, :class:`~libcst.BaseBinaryOp` is defined purely for typing and isinstance
checks.

.. class:: libcst.BaseBinaryOp

Comparison Operators
^^^^^^^^^^^^^^^^^^^^

Nodes that are used with :class:`~libcst.Comparison` to perform some comparison
operation.

.. class:: libcst.Equal
.. class:: libcst.GreaterThan
.. class:: libcst.GreaterThanEqual
.. class:: libcst.In
.. class:: libcst.Is
.. class:: libcst.LessThan
.. autoclass:: libcst.LessThanEqual

.. autoclass:: libcst.NotEqual

.. class:: libcst.IsNot
.. autoclass:: libcst.NotIn

In addition, :class:`~libcst.BaseCompOp` is defined purely for typing and isinstance
checks.

.. class:: libcst.BaseCompOp

Augmented Assignment Operators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Nodes that are used with :class:`~libcst.AugAssign` to perform some agumented
assignment.

.. class:: libcst.AddAssign
.. class:: libcst.BitAndAssign
.. class:: libcst.BitOrAssign
.. class:: libcst.BitXorAssign
.. class:: libcst.DivideAssign
.. class:: libcst.FloorDivideAssign
.. class:: libcst.LeftShiftAssign
.. class:: libcst.MatrixMultiplyAssign
.. class:: libcst.ModuloAssign
.. class:: libcst.MultiplyAssign
.. class:: libcst.PowerAssign
.. class:: libcst.RightShiftAssign
.. autoclass:: libcst.SubtractAssign

In addition, :class:`~libcst.BaseAugOp` is defined purely for typing and isinstance
checks.

.. class:: libcst.BaseAugOp

Miscellaneous
-------------

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

Whitespace
----------

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

Maybe Sentinel
--------------

.. autoclass:: libcst.MaybeSentinel