class ClassDef(_base_nodes.FilterStmtsBaseNode, LocalsDictNodeNG, _base_nodes.Statement): (source)
Class representing an :class:`ast.ClassDef` node. >>> import astroid >>> node = astroid.extract_node(''' class Thing: def my_meth(self, arg): return arg + self.offset ''') >>> node <ClassDef.Thing l.2 at 0x7f23b2e9e748>
Method | __init__ |
:param name: The name of the class. :type name: str or None |
Method | ancestors |
Iterate over the base classes in prefixed depth first order. |
Method | block |
Get a range from the given line number to where this node ends. |
Method | bool |
Determine the boolean value of this node. |
Method | callable |
Whether this node defines something that is callable. |
Method | declared |
Return the explicit declared metaclass for the current class. |
Method | display |
A human readable type of this node. |
Method | doc |
Undocumented |
Method | frame |
The node's frame node. |
Method | get |
Get the child nodes below this node. |
Method | getattr |
Get an attribute from this class, using Python's attribute semantic. |
Method | getitem |
Return the inference of a subscript. |
Method | has |
Whether this class directly inherits from the given node. |
Method | has |
Check if the class has a custom __getattr__ or __getattribute__. |
Method | has |
Undocumented |
Method | igetattr |
Infer the possible values of the given variable. |
Method | implicit |
Get implicitly defined class definition locals. |
Method | implicit |
Get the implicit metaclass of the current class. |
Method | implicit |
Undocumented |
Method | infer |
infer what a class is returning when called |
Method | instance |
Get the list of nodes associated to the given attribute name. |
Method | instance |
Iterate over the parents that define the given name as an attribute. |
Method | instantiate |
Get an :class:`Instance` of the :class:`ClassDef` node. |
Method | is |
Whether this class is a subtype of the given type. |
Method | local |
Get the list of assign nodes associated to the given name. |
Method | local |
Iterate over the parents that define the given name. |
Method | metaclass |
Get the metaclass of this class. |
Method | methods |
Iterate over all of the method defined in this class and its parents. |
Method | mro |
Get the method resolution order, using C3 linearization. |
Method | mymethods |
Iterate over all of the method defined in this class only. |
Method | postinit |
Do some setup after initialisation. |
Method | pytype |
Get the name of the type that this node represents. |
Method | scope |
Lookup where the given name is assigned. |
Method | slots |
Get all the slots for this node. |
Class Variable | hide |
Undocumented |
Class Variable | infer |
Undocumented |
Class Variable | newstyle |
Undocumented |
Class Variable | special |
The names of special attributes that this class has. |
Class Variable | type |
Undocumented |
Instance Variable | bases |
What the class inherits from. |
Instance Variable | body |
The contents of the class body. |
Instance Variable | decorators |
The decorators that are applied to this class. |
Instance Variable | doc |
The doc node associated with this node. |
Instance Variable | instance |
Undocumented |
Instance Variable | is |
Whether this class is a dataclass. |
Instance Variable | keywords |
The keywords given to the class definition. |
Instance Variable | locals |
A map of the name of a local variable to the node defining it. |
Instance Variable | name |
The name of the class. |
Instance Variable | position |
Position of keyword(s) and name. |
Property | basenames |
The names of the parent classes |
Property | blockstart |
The line on which the beginning of this block ends. |
Property | doc |
The class docstring. |
Property | fromlineno |
The first line that this node appears on in the source code. |
Method | _compute |
Undocumented |
Method | _find |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _infer |
Undocumented |
Method | _inferred |
Undocumented |
Method | _islots |
Return an iterator with the inferred slots. |
Method | _metaclass |
Search the given name in the implicit and the explicit metaclass. |
Method | _newstyle |
Undocumented |
Method | _slots |
Undocumented |
Class Variable | _astroid |
Node attributes that contain child nodes. |
Class Variable | _other |
Node attributes that do not contain child nodes. |
Class Variable | _other |
Attributes that contain AST-dependent fields. |
Class Variable | _type |
Undocumented |
Instance Variable | _doc |
The class docstring. |
Instance Variable | _metaclass |
Undocumented |
Instance Variable | _metaclass |
Undocumented |
Instance Variable | _newstyle |
Undocumented |
Inherited from LocalsDictNodeNG
:
Method | __contains__ |
Check if a local is defined in this scope. |
Method | __getitem__ |
The first node the defines the given local. |
Method | __iter__ |
Iterate over the names of locals defined in this scoped node. |
Method | add |
Append a child that should alter the locals of this scope node. |
Method | items |
Get the names of the locals and the node that defines the local. |
Method | keys |
The names of locals defined in this scoped node. |
Method | qname |
Get the 'qualified' name of the node. |
Method | scope |
The first parent node defining a new scope. |
Method | set |
Define that the given name is declared in the given statement node. |
Method | values |
The nodes that define the locals in this scoped node. |
Method | _append |
append a child, linking it in the tree |
Method | _scope |
XXX method for interfacing the scope lookup |
Inherited from LookupMixIn
(via LocalsDictNodeNG
):
Method | ilookup |
Lookup the inferred values of the given variable. |
Method | lookup |
Lookup where the given variable is assigned. |
Inherited from NodeNG
(via LocalsDictNodeNG
, LookupMixIn
):
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | accept |
Visit this node using the given visitor. |
Method | as |
Get the source code that this node represents. |
Method | child |
Search for the sequence that contains this child. |
Method | eq |
Undocumented |
Method | infer |
Get a generator of the inferred values. |
Method | inferred |
Get a list of the inferred values. |
Method | last |
An optimized version of list(get_children())[-1]. |
Method | locate |
Find the field of this node that contains the given child. |
Method | next |
The next sibling statement node. |
Method | node |
Yield parent, grandparent, etc until there are no more. |
Method | nodes |
Get the nodes (including this one or below) of the given types. |
Method | op |
Undocumented |
Method | op |
Undocumented |
Method | parent |
Check if this node is the parent of the given node. |
Method | previous |
The previous sibling statement. |
Method | repr |
Get a string representation of the AST from this node. |
Method | root |
Return the root node of the syntax tree. |
Method | statement |
The first parent node, including self, marked as statement node. |
Class Variable | is |
Whether this node indicates a function. |
Class Variable | is |
Undocumented |
Class Variable | is |
Whether this node indicates a statement. |
Class Variable | optional |
Whether this node optionally assigns a variable. |
Instance Variable | col |
The column that this node appears on in the source code. |
Instance Variable | end |
The end column this node appears on in the source code. |
Instance Variable | end |
The last line this node appears on in the source code. |
Instance Variable | lineno |
The line that this node appears on in the source code. |
Instance Variable | parent |
The parent node in the syntax tree. |
Property | tolineno |
The last line that this node appears on in the source code. |
Method | _fixed |
Attempt to find the line that this node appears on. |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _infer |
We don't know how to resolve a statement by default. |
Method | _infer |
Undocumented |
Method | _repr |
Get a name for nice representation. |
Class Variable | _explicit |
Undocumented |
def __init__(self, name=None, doc:
str|None
= None, lineno=None, col_offset=None, parent=None, *, end_lineno=None, end_col_offset=None):
(source)
¶
astroid.nodes.NodeNG.__init__
:param name: The name of the class. :type name: str or None :param doc: The class docstring. :param lineno: The line that this node appears on in the source code. :type lineno: int or None :param col_offset: The column that this node appears on in the source code. :type col_offset: int or None :param parent: The parent node in the syntax tree. :type parent: NodeNG or None :param end_lineno: The last line this node appears on in the source code. :type end_lineno: Optional[int] :param end_col_offset: The end column this node appears on in the source code. Note: This is after the last symbol. :type end_col_offset: Optional[int]
bool
= True, context: InferenceContext|None
= None) -> Generator[ ClassDef, None, None]
:
(source)
¶
Iterate over the base classes in prefixed depth first order. :param recurs: Whether to recurse or return direct ancestors only. :returns: The base classes
astroid.nodes.NodeNG.block_range
Get a range from the given line number to where this node ends. :param lineno: Unused. :type lineno: int :returns: The range of line numbers that this node belongs to, :rtype: tuple(int, int)
astroid.nodes.NodeNG.bool_value
Determine the boolean value of this node. :returns: The boolean value of this node. For a :class:`ClassDef` this is always ``True``.
astroid.nodes.NodeNG.callable
Whether this node defines something that is callable. :returns: Whether this defines something that is callable. For a :class:`ClassDef` this is always ``True``.
Return the explicit declared metaclass for the current class. An explicit declared metaclass is defined either by passing the ``metaclass`` keyword argument in the class definition line (Python 3) or (Python 2) by having a ``__metaclass__`` class attribute, or if there are no explicit bases but there is a global ``__metaclass__`` variable. :returns: The metaclass of this class, or None if one could not be found.
astroid.nodes.NodeNG.frame
The node's frame node. A frame node is a :class:`Module`, :class:`FunctionDef`, :class:`ClassDef` or :class:`Lambda`. :returns: The node itself.
str
, context: InferenceContext|None
= None, class_context: bool
= True) -> list[ SuccessfulInferenceResult]
:
(source)
¶
Get an attribute from this class, using Python's attribute semantic. This method doesn't look in the :attr:`instance_attrs` dictionary since it is done by an :class:`Instance` proxy at inference time. It may return an :class:`Uninferable` object if the attribute has not been found, but a ``__getattr__`` or ``__getattribute__`` method is defined. If ``class_context`` is given, then it is considered that the attribute is accessed from a class context, e.g. ClassDef.attribute, otherwise it might have been accessed from an instance as well. If ``class_context`` is used in that case, then a lookup in the implicit metaclass and the explicit metaclass will be done. :param name: The attribute to look for. :param class_context: Whether the attribute can be accessed statically. :returns: The attribute. :raises AttributeInferenceError: If the attribute cannot be inferred.
Return the inference of a subscript. This is basically looking up the method in the metaclass and calling it. :returns: The inferred value of a subscript to this class. :rtype: NodeNG :raises AstroidTypeError: If this class does not define a ``__getitem__`` method.
astroid.nodes.NodeNG.has_base
Whether this class directly inherits from the given node. :param node: The node to check for. :type node: NodeNG :returns: Whether this class directly inherits from the given node.
Check if the class has a custom __getattr__ or __getattribute__. If any such method is found and it is not from builtins, nor from an extension module, then the function will return True. :returns: Whether the class has a custom __getattr__ or __getattribute__.
str
, context: InferenceContext|None
= None, class_context: bool
= True) -> Iterator[ InferenceResult]
:
(source)
¶
Infer the possible values of the given variable. :param name: The name of the variable to infer. :returns: The inferred possible values.
Get implicitly defined class definition locals. :returns: the the name and Const pair for each local :rtype: tuple(tuple(str, node_classes.Const), ...)
Get the implicit metaclass of the current class. For newstyle classes, this will return an instance of builtins.type. For oldstyle classes, it will simply return None, since there's no implicit metaclass there. :returns: The metaclass. :rtype: builtins.type or None
Get the list of nodes associated to the given attribute name. Assignments are looked for in both this class and in parents. :returns: The list of assignments to the given name. :rtype: list(NodeNG) :raises AttributeInferenceError: If no attribute with this name can be found in this class or parent classes.
Iterate over the parents that define the given name as an attribute. :param name: The name to find definitions for. :type name: str :returns: The parents that define the given name as an instance attribute. :rtype: iterable(NodeNG)
astroid.nodes.NodeNG.instantiate_class
Get an :class:`Instance` of the :class:`ClassDef` node. :returns: An :class:`Instance` of the :class:`ClassDef` node
Whether this class is a subtype of the given type. :param type_name: The name of the type of check against. :type type_name: str :returns: Whether this class is a subtype of the given type.
Get the list of assign nodes associated to the given name. Assignments are looked for in both this class and in parents. :returns: The list of assignments to the given name. :rtype: list(NodeNG) :raises AttributeInferenceError: If no attribute with this name can be found in this class or parent classes.
Iterate over the parents that define the given name. :param name: The name to find definitions for. :type name: str :returns: The parents that define the given name. :rtype: iterable(NodeNG)
Get the metaclass of this class. If this class does not define explicitly a metaclass, then the first defined metaclass in ancestors will be used instead. :returns: The metaclass of this class.
Iterate over all of the method defined in this class and its parents. :returns: The methods defined on the class. :rtype: iterable(FunctionDef)
Get the method resolution order, using C3 linearization. :returns: The list of ancestors, sorted by the mro. :rtype: list(NodeNG) :raises DuplicateBasesError: Duplicate bases in the same class base :raises InconsistentMroError: A class' MRO is inconsistent
Iterate over all of the method defined in this class only. :returns: The methods defined on the class. :rtype: iterable(FunctionDef)
NodeNG|None
= None, keywords=None, *, position: Position|None
= None, doc_node: Const|None
= None):
(source)
¶
Do some setup after initialisation. :param bases: What the class inherits from. :type bases: list(NodeNG) :param body: The contents of the class body. :type body: list(NodeNG) :param decorators: The decorators that are applied to this class. :type decorators: Decorators or None :param newstyle: Whether this is a new style class or not. :type newstyle: bool or None :param metaclass: The metaclass of this class. :param keywords: The keywords given to the class definition. :type keywords: list(Keyword) or None :param position: Position of class keyword and name. :param doc_node: The doc node associated with this node.
Lookup where the given name is assigned. :param node: The node to look for assignments up to. Any assignments after the given node are ignored. :type node: NodeNG :param name: The name to find assignments for. :type name: str :param offset: The line offset to filter statements up to. :type offset: int :returns: This scope node and the list of assignments associated to the given name according to the scope where it has been found (locals, globals or builtin). :rtype: tuple(str, list(NodeNG))
Get all the slots for this node. :returns: The names of slots for this class. If the class doesn't define any slot, through the ``__slots__`` variable, then this function will return a None. Also, it will return None in the case the slots were not inferred. :rtype: list(str) or None
The keywords given to the class definition. This is usually for :pep:`3115` style metaclass declaration. :type: list(Keyword) or None
astroid.nodes.NodeNG.position
Position of keyword(s) and name. Used as fallback for block nodes which might not provide good enough positional information. E.g. ClassDef, FunctionDef.
The names of the parent classes Names are given in the order they appear in the class definition. :type: list(str)
astroid.nodes.NodeNG.fromlineno
The first line that this node appears on in the source code.
set[ ClassDef]|None
= None, context: InferenceContext|None
= None) -> NodeNG|None
:
(source)
¶
Undocumented
astroid.nodes.NodeNG._astroid_fields
Node attributes that contain child nodes. This is redefined in most concrete classes.