Skip to main content

PythonClassDefinition AST Python Object

The PythonClassDefinition object matches a Python class definition.

The astType value for this node is classdefinition.

Code Pattern

This AST element captures the following code.

class MyClass:
def __init__(self):
pass


def my_method(self, argument):
pass

Attributes

  • name (type AstString): name of the class
  • decorators: decorators for this class (array of type PythonDecorator)
  • parentClasses (array of type AstString): parents of the class (e.g. classes inherited from this class)
  • content (any type that inherits AstElement): the content of the class (methods, attributes, etc)
info

To know what is the type of left or right, use the astType to distinguish.

For example, to check if the left node is a string, just use the following code:

if (node.left.astType === "string") {
....
}