Nodes

Every available node class.

All nodes inherit from NodeNG.

class astroid.nodes.AnnAssign(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.AnnAssign node.

An AnnAssign is an assignment with a type annotation.

>>> node = astroid.extract_node('variable: List[int] = range(10)')
>>> node
<AnnAssign l.1 at 0x7effe1d4c630>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(target, annotation, simple, value=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

annotation: Optional[astroid.node_classes.NodeNG]

The type annotation of what is being assigned to.

simple: Optional[int]

Whether target is a pure name or a complex statement.

target: Optional[astroid.node_classes.NodeNG]

What is being assigned to.

value: Optional[astroid.node_classes.NodeNG]

The value being assigned to the variables.

class astroid.nodes.Arguments(vararg=None, kwarg=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.NodeNG

Class representing an ast.arguments node.

An Arguments node represents that arguments in a function definition.

>>> node = astroid.extract_node('def foo(bar): pass')
>>> node
<FunctionDef.foo l.1 at 0x7effe1db8198>
>>> node.args
<Arguments l.1 at 0x7effe1db82e8>
Parameters
  • vararg (Optional[str]) – The name of the variable length arguments.

  • kwarg (Optional[str]) – The name of the variable length keyword arguments.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
default_value(argname)[source]

Get the default value for an argument.

Parameters

argname (str) – The name of the argument to get the default value for.

Raises

NoDefault – If there is no default value defined for the given argument.

find_argname(argname, rec=False)[source]

Get the index and AssignName node for given name.

Parameters
  • argname (str) – The name of the argument to search for.

  • rec (bool) – Whether or not to include arguments in unpacked tuples in the search.

Returns

The index and node for the argument.

Return type

tuple(str or None, AssignName or None)

format_args()[source]

Get the arguments formatted as string.

Returns

The formatted arguments.

Return type

str

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

is_argument(name)[source]

Check if the given name is defined in the arguments.

Parameters

name (str) – The name to check for.

Returns

True if the given name is defined in the arguments, False otherwise.

Return type

bool

postinit(args, defaults, kwonlyargs, kw_defaults, annotations, posonlyargs=None, kwonlyargs_annotations=None, posonlyargs_annotations=None, varargannotation=None, kwargannotation=None, type_comment_args=None, type_comment_kwonlyargs=None, type_comment_posonlyargs=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

annotations: List[Optional[astroid.node_classes.NodeNG]]

The type annotations of arguments that can be passed positionally.

args: List[astroid.node_classes.AssignName]

The names of the required arguments.

arguments

<wrapped by the cachedproperty decorator> Get all the arguments for this node, including positional only and positional and keyword

defaults: List[astroid.node_classes.NodeNG]

The default values for arguments that can be passed positionally.

fromlineno

<wrapped by the cachedproperty decorator> The first line that this node appears on in the source code.

type

int or None

kw_defaults: List[Optional[astroid.node_classes.NodeNG]]

The default values for keyword arguments that cannot be passed positionally.

kwarg: Optional[str]

The name of the variable length keyword arguments.

kwargannotation: Optional[astroid.node_classes.NodeNG]

The type annotation for the variable length keyword arguments.

kwonlyargs: List[astroid.node_classes.AssignName]

The keyword arguments that cannot be passed positionally.

kwonlyargs_annotations: List[Optional[astroid.node_classes.NodeNG]]

The type annotations of arguments that cannot be passed positionally.

posonlyargs: List[astroid.node_classes.AssignName]

The arguments that can only be passed positionally.

posonlyargs_annotations: List[Optional[astroid.node_classes.NodeNG]]

The type annotations of arguments that can only be passed positionally.

type_comment_args: List[Optional[astroid.node_classes.NodeNG]]

The type annotation, passed by a type comment, of each argument.

If an argument does not have a type comment, the value for that argument will be None.

type_comment_kwonlyargs: List[Optional[astroid.node_classes.NodeNG]]

The type annotation, passed by a type comment, of each keyword only argument.

If an argument does not have a type comment, the value for that argument will be None.

type_comment_posonlyargs: List[Optional[astroid.node_classes.NodeNG]]

The type annotation, passed by a type comment, of each positional argument.

If an argument does not have a type comment, the value for that argument will be None.

vararg: Optional[str]

The name of the variable length arguments.

varargannotation: Optional[astroid.node_classes.NodeNG]

The type annotation for the variable length arguments.

class astroid.nodes.Assert(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing an ast.Assert node.

An Assert node represents an assert statement.

>>> node = astroid.extract_node('assert len(things) == 10, "Not enough things"')
>>> node
<Assert l.1 at 0x7effe1d527b8>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(test=None, fail=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

fail: Optional[astroid.node_classes.NodeNG]

The message shown when the assertion fails.

test: Optional[astroid.node_classes.NodeNG]

The test that passes or fails the assertion.

class astroid.nodes.Assign(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.Assign node.

An Assign is a statement where something is explicitly asssigned to.

>>> node = astroid.extract_node('variable = range(10)')
>>> node
<Assign l.1 at 0x7effe1db8550>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(targets=None, value=None, type_annotation=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

targets: List[astroid.node_classes.NodeNG]

What is being assigned to.

type_annotation: Optional[astroid.node_classes.NodeNG]

If present, this will contain the type annotation passed by a type comment

value: Optional[astroid.node_classes.NodeNG]

The value being assigned to the variables.

class astroid.nodes.AssignAttr(attrname=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Variation of ast.Assign representing assignment to an attribute.

>>> node = astroid.extract_node('self.attribute = range(10)')
>>> node
<Assign l.1 at 0x7effe1d521d0>
>>> list(node.get_children())
[<AssignAttr.attribute l.1 at 0x7effe1d52320>, <Call l.1 at 0x7effe1d522e8>]
>>> list(node.get_children())[0].as_string()
'self.attribute'
Parameters
  • attrname (Optional[str]) – The name of the attribute being assigned to.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

infer_lhs(context=None)

infer an Attribute node by using getattr on the associated object

postinit(expr=None)[source]

Do some setup after initialisation.

Parameters

expr (Optional[astroid.node_classes.NodeNG]) – What has the attribute that is being assigned to.

Return type

None

attrname: Optional[str]

The name of the attribute being assigned to.

expr: Optional[astroid.node_classes.NodeNG]

What has the attribute that is being assigned to.

class astroid.nodes.AssignName(name=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.LookupMixIn, astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Variation of ast.Assign representing assignment to a name.

An AssignName is the name of something that is assigned to. This includes variables defined in a function signature or in a loop.

>>> node = astroid.extract_node('variable = range(10)')
>>> node
<Assign l.1 at 0x7effe1db8550>
>>> list(node.get_children())
[<AssignName.variable l.1 at 0x7effe1db8748>, <Call l.1 at 0x7effe1db8630>]
>>> list(node.get_children())[0].as_string()
'variable'
Parameters
  • name (Optional[str]) – The name that is assigned to.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
infer_lhs(context=None)

infer a Name: use name lookup rules

name: Optional[str]

The name that is assigned to.

class astroid.nodes.AsyncFor(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.For

Class representing an ast.AsyncFor node.

An AsyncFor is an asynchronous For built with the async keyword.

>>> node = astroid.extract_node('''
async def func(things):
    async for thing in things:
        print(thing)
''')
>>> node
<AsyncFunctionDef.func l.2 at 0x7f23b2e416d8>
>>> node.body[0]
<AsyncFor l.3 at 0x7f23b2e417b8>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

class astroid.nodes.AsyncFunctionDef(name=None, doc=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes.FunctionDef

Class representing an ast.FunctionDef node.

A AsyncFunctionDef is an asynchronous function created with the async keyword.

>>> node = astroid.extract_node('''
async def func(things):
    async for thing in things:
        print(thing)
''')
>>> node
<AsyncFunctionDef.func l.2 at 0x7f23b2e416d8>
>>> node.body[0]
<AsyncFor l.3 at 0x7f23b2e417b8>
Parameters
  • name (str or None) – The name of the function.

  • doc (str or None) – The function’s docstring.

  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

class astroid.nodes.AsyncWith(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.With

Asynchronous with built with the async keyword.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

class astroid.nodes.Attribute(attrname=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Attribute node.

Parameters
  • attrname (Optional[str]) – The name of the attribute.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(expr=None)[source]

Do some setup after initialisation.

Parameters

expr (Name or None) – The name that this node represents.

Return type

None

attrname: Optional[str]

The name of the attribute.

expr: Optional[astroid.node_classes.NodeNG]

The name that this node represents.

Type

Name or None

class astroid.nodes.AugAssign(op=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.AugAssign node.

An AugAssign is an assignment paired with an operator.

>>> node = astroid.extract_node('variable += 1')
>>> node
<AugAssign l.1 at 0x7effe1db4d68>
Parameters
  • op (Optional[str]) – The operator that is being combined with the assignment. This includes the equals sign.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(target=None, value=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

type_errors(context=None)[source]

Get a list of type errors which can occur during inference.

Each TypeError is represented by a BadBinaryOperationMessage , which holds the original exception.

Returns

The list of possible type errors.

Return type

list(BadBinaryOperationMessage)

op: Optional[str]

The operator that is being combined with the assignment.

This includes the equals sign.

target: Optional[astroid.node_classes.NodeNG]

What is being assigned to.

value: Optional[astroid.node_classes.NodeNG]

The value being assigned to the variable.

class astroid.nodes.Await(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Await node.

An Await is the await keyword.

>>> node = astroid.extract_node('''
async def func(things):
    await other_func()
''')
>>> node
<AsyncFunctionDef.func l.2 at 0x7f23b2e41748>
>>> node.body[0]
<Expr l.3 at 0x7f23b2e419e8>
>>> list(node.body[0].get_children())[0]
<Await l.3 at 0x7f23b2e41a20>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – What to wait for.

Return type

None

value: Optional[astroid.node_classes.NodeNG]

What to wait for.

class astroid.nodes.BinOp(op=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.BinOp node.

A BinOp node is an application of a binary operator.

>>> node = astroid.extract_node('a + b')
>>> node
<BinOp l.1 at 0x7f23b2e8cfd0>
Parameters
  • op (Optional[str]) – The operator.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

op_left_associative()[source]
op_precedence()[source]
postinit(left=None, right=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

type_errors(context=None)[source]

Get a list of type errors which can occur during inference.

Each TypeError is represented by a BadBinaryOperationMessage, which holds the original exception.

Returns

The list of possible type errors.

Return type

list(BadBinaryOperationMessage)

left: Optional[astroid.node_classes.NodeNG]

What is being applied to the operator on the left side.

op: Optional[str]

The operator.

right: Optional[astroid.node_classes.NodeNG]

What is being applied to the operator on the right side.

class astroid.nodes.BoolOp(op=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.BoolOp node.

A BoolOp is an application of a boolean operator.

>>> node = astroid.extract_node('a and b')
>>> node
<BinOp l.1 at 0x7f23b2e71c50>
Parameters
  • op (Optional[str]) – The operator.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

op_precedence()[source]
postinit(values=None)[source]

Do some setup after initialisation.

Parameters

values (Optional[List[astroid.node_classes.NodeNG]]) – The values being applied to the operator.

Return type

None

op: Optional[str]

The operator.

values: List[astroid.node_classes.NodeNG]

The values being applied to the operator.

class astroid.nodes.Break(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Break node.

>>> node = astroid.extract_node('break')
>>> node
<Break l.1 at 0x7f23b2e9e5c0>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

class astroid.nodes.Call(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Call node.

A Call node is a call to a function, method, etc.

>>> node = astroid.extract_node('function()')
>>> node
<Call l.1 at 0x7f23b2e71eb8>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(func=None, args=None, keywords=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

args: List[astroid.node_classes.NodeNG]

The positional arguments being given to the call.

func: Optional[astroid.node_classes.NodeNG]

What is being called.

keywords: List[Keyword]

The keyword arguments being given to the call.

property kwargs: List[astroid.node_classes.Keyword]

The keyword arguments that unpack something.

property starargs: List[astroid.node_classes.Starred]

The positional arguments that unpack something.

class astroid.nodes.ClassDef(name=None, doc=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.FilterStmtsMixin, astroid.scoped_nodes.LocalsDictNodeNG, astroid.node_classes.Statement

Class representing an ast.ClassDef node.

>>> node = astroid.extract_node('''
class Thing:
    def my_meth(self, arg):
        return arg + self.offset
''')
>>> node
<ClassDef.Thing l.2 at 0x7f23b2e9e748>
Parameters
  • name (str or None) – The name of the class.

  • doc (str or None) – The function’s docstring.

  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

ancestors(recurs=True, context=None)[source]

Iterate over the base classes in prefixed depth first order.

Parameters

recurs (bool) – Whether to recurse or return direct ancestors only.

Returns

The base classes

Return type

iterable(NodeNG)

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – Unused.

Returns

The range of line numbers that this node belongs to,

Return type

tuple(int, int)

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a ClassDef this is always True.

Return type

bool

callable()[source]

Whether this node defines something that is callable.

Returns

True if this defines something that is callable, False otherwise. For a ClassDef this is always True.

Return type

bool

declared_metaclass(context=None)[source]

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.

Return type

NodeNG or None

display_type()[source]

A human readable type of this node.

Returns

The type of this node.

Return type

str

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

getattr(name, context=None, class_context=True)[source]

Get an attribute from this class, using Python’s attribute semantic.

This method doesn’t look in the instance_attrs dictionary since it is done by an Instance proxy at inference time. It may return an 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.

Parameters
  • name (str) – The attribute to look for.

  • class_context (bool) – Whether the attribute can be accessed statically.

Returns

The attribute.

Return type

list(NodeNG)

Raises

AttributeInferenceError – If the attribute cannot be inferred.

getitem(index, context=None)[source]

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.

Return type

NodeNG

Raises

AstroidTypeError – If this class does not define a __getitem__ method.

has_base(node)[source]

Whether this class directly inherits from the given node.

Parameters

node (NodeNG) – The node to check for.

Returns

True if this class directly inherits from the given node.

Return type

bool

has_dynamic_getattr(context=None)[source]

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

True if the class has a custom __getattr__ or __getattribute__, False otherwise.

Return type

bool

has_metaclass_hack()[source]
igetattr(name, context=None, class_context=True)[source]

Infer the possible values of the given variable.

Parameters

name (str) – The name of the variable to infer.

Returns

The inferred possible values.

Return type

iterable(NodeNG or Uninferable)

implicit_locals()[source]

Get implicitly defined class definition locals.

Returns

the the name and Const pair for each local

Return type

tuple(tuple(str, node_classes.Const), …)

implicit_metaclass()[source]

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.

Return type

builtins.type or None

implicit_parameters()[source]
infer_binary_op(opnode, operator, other, context, method)
infer_call_result(caller, context=None)[source]

infer what a class is returning when called

instance_attr(name, context=None)[source]

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.

Return type

list(NodeNG)

Raises

AttributeInferenceError – If no attribute with this name can be found in this class or parent classes.

instance_attr_ancestors(name, context=None)[source]

Iterate over the parents that define the given name as an attribute.

Parameters

name (str) – The name to find definitions for.

Returns

The parents that define the given name as an instance attribute.

Return type

iterable(NodeNG)

instantiate_class()[source]

Get an Instance of the ClassDef node.

Returns

An Instance of the ClassDef node, or self if this is not possible.

Return type

Instance or ClassDef

is_subtype_of(type_name, context=None)[source]

Whether this class is a subtype of the given type.

Parameters

type_name (str) – The name of the type of check against.

Returns

True if this class is a subtype of the given type, False otherwise.

Return type

bool

local_attr(name, context=None)[source]

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.

Return type

list(NodeNG)

Raises

AttributeInferenceError – If no attribute with this name can be found in this class or parent classes.

local_attr_ancestors(name, context=None)[source]

Iterate over the parents that define the given name.

Parameters

name (str) – The name to find definitions for.

Returns

The parents that define the given name.

Return type

iterable(NodeNG)

metaclass(context=None)[source]

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.

Return type

NodeNG or None

methods()[source]

Iterate over all of the method defined in this class and its parents.

Returns

The methods defined on the class.

Return type

iterable(FunctionDef)

mro(context=None)[source]

Get the method resolution order, using C3 linearization.

Returns

The list of ancestors, sorted by the mro.

Return type

list(NodeNG)

Raises
mymethods()[source]

Iterate over all of the method defined in this class only.

Returns

The methods defined on the class.

Return type

iterable(FunctionDef)

postinit(bases, body, decorators, newstyle=None, metaclass=None, keywords=None)[source]

Do some setup after initialisation.

Parameters
  • bases (list(NodeNG)) – What the class inherits from.

  • body (list(NodeNG)) – The contents of the class body.

  • decorators (Decorators or None) – The decorators that are applied to this class.

  • newstyle (bool or None) – Whether this is a new style class or not.

  • metaclass (NodeNG or None) – The metaclass of this class.

  • keywords (list(Keyword) or None) – The keywords given to the class definition.

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

scope_lookup(node, name, offset=0)[source]

Lookup where the given name is assigned.

Parameters
  • node (NodeNG) – The node to look for assignments up to. Any assignments after the given node are ignored.

  • name (str) – The name to find assignments for.

  • offset (int) – The line offset to filter statements up to.

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

Return type

tuple(str, list(NodeNG))

slots()[source]

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.

Return type

list(str) or None

property basenames

The names of the parent classes

Names are given in the order they appear in the class definition.

Type

list(str)

bases

What the class inherits from.

Type

list(NodeNG)

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body

The contents of the class body.

Type

list(NodeNG)

decorators = None

The decorators that are applied to this class.

Type

Decorators or None

doc

The class’ docstring.

hide = False
keywords

The keywords given to the class definition.

This is usually for PEP 3115 style metaclass declaration.

Type

list(Keyword) or None

name

The name of the class.

property newstyle

Whether this is a new style class or not

Type

bool or None

special_attributes

The names of special attributes that this class has.

Type

objectmodel.ClassModel

property type

The class type for this node.

Possible values are: class, metaclass, exception.

Type

str

class astroid.nodes.Compare(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Compare node.

A Compare node indicates a comparison.

>>> node = astroid.extract_node('a <= b <= c')
>>> node
<Compare l.1 at 0x7f23b2e9e6d8>
>>> node.ops
[('<=', <Name.b l.1 at 0x7f23b2e9e2b0>), ('<=', <Name.c l.1 at 0x7f23b2e9e390>)]
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Overridden to handle the tuple fields and skip returning the operator strings.

Returns

The children.

Return type

iterable(NodeNG)

last_child()[source]

An optimized version of list(get_children())[-1]

Returns

The last child.

Return type

NodeNG

postinit(left=None, ops=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

left: Optional[astroid.node_classes.NodeNG]

The value at the left being applied to a comparison operator.

ops: List[Tuple[str, astroid.node_classes.NodeNG]]

The remainder of the operators and their relevant right hand value.

class astroid.nodes.Comprehension(parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.comprehension node.

A Comprehension indicates the loop inside any type of comprehension including generator expressions.

>>> node = astroid.extract_node('[x for x in some_values]')
>>> list(node.get_children())
[<Name.x l.1 at 0x7f23b2e352b0>, <Comprehension l.1 at 0x7f23b2e35320>]
>>> list(node.get_children())[1].as_string()
'for x in some_values'
Parameters

parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assign_type()[source]

The type of assignment that this node performs.

Returns

The assignment type.

Return type

NodeNG

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(target=None, iter=None, ifs=None, is_async=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

ifs: List[astroid.node_classes.NodeNG]

The contents of any if statements that filter the comprehension.

is_async: Optional[bool]

Whether this is an asynchronous comprehension or not.

iter: Optional[astroid.node_classes.NodeNG]

What is iterated over by the comprehension.

optional_assign: ClassVar[bool] = True

Whether this node optionally assigns a variable.

target: Optional[astroid.node_classes.NodeNG]

What is assigned to by the comprehension.

class astroid.nodes.Const(value, lineno=None, col_offset=None, parent=None, kind=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.NodeNG, astroid.bases.Instance

Class representing any constant including num, str, bool, None, bytes.

>>> node = astroid.extract_node('(5, "This is a string.", True, None, b"bytes")')
>>> node
<Tuple.tuple l.1 at 0x7f23b2e358d0>
>>> list(node.get_children())
[<Const.int l.1 at 0x7f23b2e35940>,
<Const.str l.1 at 0x7f23b2e35978>,
<Const.bool l.1 at 0x7f23b2e359b0>,
<Const.NoneType l.1 at 0x7f23b2e359e8>,
<Const.bytes l.1 at 0x7f23b2e35a20>]
Parameters
  • value (Any) – The value that the constant represents.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

  • kind (Optional[str]) – The string prefix. “u” for u-prefixed strings and None otherwise. Python 3.8+ only.

Return type

None

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node.

Return type

bool

getitem(index, context=None)[source]

Get an item from this node if subscriptable.

Parameters

index (Const or Slice) – The node to use as a subscript index.

Raises

AstroidTypeError – When the given index cannot be used as a subscript index, or if this node is not subscriptable.

has_dynamic_getattr()[source]

Check if the node has a custom __getattr__ or __getattribute__.

Returns

True if the class has a custom __getattr__ or __getattribute__, False otherwise. For a Const this is always False.

Return type

bool

infer_binary_op(opnode, operator, other, context, _)
infer_unary_op(op)
itered()[source]

An iterator over the elements this node contains.

Returns

The contents of this node.

Return type

iterable(Const)

Raises

TypeError – If this node does not represent something that is iterable.

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

kind: Optional[str]

“The string prefix. “u” for u-prefixed strings and None otherwise. Python 3.8+ only.

value: Any

The value that the constant represents.

class astroid.nodes.Continue(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Continue node.

>>> node = astroid.extract_node('continue')
>>> node
<Continue l.1 at 0x7f23b2e35588>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

class astroid.nodes.Decorators(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

A node representing a list of decorators.

A Decorators is the decorators that are applied to a method or function.

>>> node = astroid.extract_node('''
@property
def my_property(self):
    return 3
''')
>>> node
<FunctionDef.my_property l.2 at 0x7f23b2e35d30>
>>> list(node.get_children())[0]
<Decorators l.1 at 0x7f23b2e35d68>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(nodes)[source]

Do some setup after initialisation.

Parameters

nodes (list(Name or Call)) – The decorators that this node contains.

Return type

None

scope()[source]

The first parent node defining a new scope.

Returns

The first parent scope node.

Return type

Module or FunctionDef or ClassDef or Lambda or GenExpr

nodes: List[astroid.node_classes.NodeNG]

The decorators that this node contains.

Type

list(Name or Call) or None

class astroid.nodes.DelAttr(attrname=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Variation of ast.Delete representing deletion of an attribute.

>>> node = astroid.extract_node('del self.attr')
>>> node
<Delete l.1 at 0x7f23b2e35f60>
>>> list(node.get_children())[0]
<DelAttr.attr l.1 at 0x7f23b2e411d0>
Parameters
  • attrname (Optional[str]) – The name of the attribute that is being deleted.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(expr=None)[source]

Do some setup after initialisation.

Parameters

expr (Name or None) – The name that this node represents.

Return type

None

attrname: Optional[str]

The name of the attribute that is being deleted.

expr: Optional[astroid.node_classes.NodeNG]

The name that this node represents.

Type

Name or None

class astroid.nodes.DelName(name=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.LookupMixIn, astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Variation of ast.Delete representing deletion of a name.

A DelName is the name of something that is deleted.

>>> node = astroid.extract_node("del variable #@")
>>> list(node.get_children())
[<DelName.variable l.1 at 0x7effe1da4d30>]
>>> list(node.get_children())[0].as_string()
'variable'
Parameters
  • name (Optional[str]) – The name that is being deleted.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

name: Optional[str]

The name that is being deleted.

class astroid.nodes.Delete(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.Delete node.

A Delete is a del statement this is deleting something.

>>> node = astroid.extract_node('del self.attr')
>>> node
<Delete l.1 at 0x7f23b2e35f60>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(targets=None)[source]

Do some setup after initialisation.

Parameters

targets (Optional[List[astroid.node_classes.NodeNG]]) – What is being deleted.

Return type

None

targets: List[astroid.node_classes.NodeNG]

What is being deleted.

class astroid.nodes.Dict(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG, astroid.objects.DictInstance

Class representing an ast.Dict node.

A Dict is a dictionary that is created with {} syntax.

>>> node = astroid.extract_node('{1: "1"}')
>>> node
<Dict.dict l.1 at 0x7f23b2e35cc0>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node.

Return type

bool

classmethod from_elements(items=None)[source]

Create a Dict of constants from a live dictionary.

Parameters

items (dict) – The items to store in the node.

Returns

The created dictionary node.

Return type

Dict

get_children()[source]

Get the key and value nodes below this node.

Children are returned in the order that they are defined in the source code, key first then the value.

Returns

The children.

Return type

iterable(NodeNG)

getitem(index, context=None)[source]

Get an item from this node.

Parameters

index (Const or Slice) – The node to use as a subscript index.

Raises
  • AstroidTypeError – When the given index cannot be used as a subscript index, or if this node is not subscriptable.

  • AstroidIndexError – If the given index does not exist in the dictionary.

infer_unary_op(op)
itered()[source]

An iterator over the keys this node contains.

Returns

The keys of this node.

Return type

iterable(NodeNG)

last_child()[source]

An optimized version of list(get_children())[-1]

Returns

The last child, or None if no children exist.

Return type

NodeNG or None

postinit(items)[source]

Do some setup after initialisation.

Parameters

items (List[Tuple[astroid.node_classes.NodeNG, astroid.node_classes.NodeNG]]) – The key-value pairs contained in the dictionary.

Return type

None

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

items: List[Tuple[astroid.node_classes.NodeNG, astroid.node_classes.NodeNG]]

The key-value pairs contained in the dictionary.

class astroid.nodes.DictComp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes.ComprehensionScope

Class representing an ast.DictComp node.

>>> node = astroid.extract_node('{k:v for k, v in things if k > v}')
>>> node
<DictComp l.1 at 0x7f23b2e41d68>
Parameters
  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a DictComp this is always Uninferable.

Return type

Uninferable

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(key=None, value=None, generators=None)[source]

Do some setup after initialisation.

Parameters
  • key (NodeNG or None) – What produces the keys.

  • value (NodeNG or None) – What produces the values.

  • generators (list(Comprehension) or None) – The generators that are looped through.

generators = None

The generators that are looped through.

Type

list(Comprehension) or None

key = None

What produces the keys.

Type

NodeNG or None

value = None

What produces the values.

Type

NodeNG or None

class astroid.nodes.DictUnpack(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.NodeNG

Represents the unpacking of dicts into dicts using PEP 448.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

class astroid.nodes.Ellipsis(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.NodeNG

Class representing an ast.Ellipsis node.

An Ellipsis is the ... syntax.

Deprecated since v2.6.0 - Use Const instead. Will be removed with the release v2.7.0

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

class astroid.nodes.EmptyNode(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.NodeNG

Holds an arbitrary object in the LocalsDictNodeNG.locals.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

has_underlying_object()
object = None
class astroid.nodes.EvaluatedObject(original, value)[source]

Bases: astroid.node_classes.NodeNG

Contains an object that has already been inferred

This class is useful to pre-evaluate a particular node, with the resulting class acting as the non-evaluated node.

Parameters
  • lineno – The line that this node appears on in the source code.

  • col_offset – The column that this node appears on in the source code.

  • parent – The parent node in the syntax tree.

  • original (astroid.node_classes.NodeNG) –

  • value (Union[astroid.node_classes.NodeNG, Uninferable]) –

Return type

None

infer(context=None, **kwargs)[source]

Get a generator of the inferred values.

This is the main entry point to the inference system.

If the instance has some explicit inference function set, it will be called instead of the default interface.

Returns

The inferred values.

Return type

iterable

name = 'EvaluatedObject'
original: astroid.node_classes.NodeNG

The original node that has already been evaluated

value: Union[astroid.node_classes.NodeNG, Uninferable]

The inferred value

class astroid.nodes.ExceptHandler(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.ExceptHandler. node.

An ExceptHandler is an except block on a try-except.

>>> node = astroid.extract_node('''
    try:
        do_something()
    except Exception as error:
        print("Error!")
    ''')
>>> node
<TryExcept l.2 at 0x7f23b2e9d908>
>>> >>> node.handlers
[<ExceptHandler l.4 at 0x7f23b2e9e860>]
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
catch(exceptions)[source]

Check if this node handles any of the given

Parameters

exceptions (Optional[List[str]]) – The names of the exceptions to check for.

Return type

bool

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(type=None, name=None, body=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

:param body:The contents of the block.

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the block.

name: Optional[astroid.node_classes.AssignName]

The name that the caught exception is assigned to.

type: Optional[astroid.node_classes.NodeNG]

The types that the block handles.

Type

Tuple or NodeNG or None

class astroid.nodes.Expr(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing an ast.Expr node.

An Expr is any expression that does not have its value used or stored.

>>> node = astroid.extract_node('method()')
>>> node
<Call l.1 at 0x7f23b2e352b0>
>>> node.parent
<Expr l.1 at 0x7f23b2e35278>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – What the expression does.

Return type

None

value: Optional[astroid.node_classes.NodeNG]

What the expression does.

class astroid.nodes.ExtSlice(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.ExtSlice node.

An ExtSlice is a complex slice expression.

Deprecated since v2.6.0 - Now part of the Subscript node. Will be removed with the release of v2.7.0

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

class astroid.nodes.For(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.For node.

>>> node = astroid.extract_node('for thing in things: print(thing)')
>>> node
<For l.1 at 0x7f23b2e8cf28>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(target=None, iter=None, body=None, orelse=None, type_annotation=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the body of the loop.

iter: Optional[astroid.node_classes.NodeNG]

What the loop iterates over.

optional_assign: ClassVar[bool] = True

Whether this node optionally assigns a variable.

This is always True for For nodes.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block of the loop.

target: Optional[astroid.node_classes.NodeNG]

What the loop assigns to.

type_annotation: Optional[astroid.node_classes.NodeNG]

If present, this will contain the type annotation passed by a type comment

class astroid.nodes.FormattedValue(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.FormattedValue node.

Represents a PEP 498 format string.

>>> node = astroid.extract_node('f"Format {type_}"')
>>> node
<JoinedStr l.1 at 0x7f23b2e4ed30>
>>> node.values
[<Const.str l.1 at 0x7f23b2e4eda0>, <FormattedValue l.1 at 0x7f23b2e4edd8>]
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value, conversion=None, format_spec=None)[source]

Do some setup after initialisation.

Parameters
  • value (astroid.node_classes.NodeNG) – The value to be formatted into the string.

  • conversion (Optional[int]) – The type of formatting to be applied to the value.

  • format_spec (JoinedStr or None) – The formatting to be applied to the value.

Return type

None

conversion: Optional[int]

The type of formatting to be applied to the value.

format_spec: Optional[astroid.node_classes.NodeNG]

The formatting to be applied to the value.

Type

JoinedStr or None

value: astroid.node_classes.NodeNG

The value to be formatted into the string.

class astroid.nodes.FunctionDef(name=None, doc=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.node_classes.Statement, astroid.scoped_nodes.Lambda

Class representing an ast.FunctionDef.

>>> node = astroid.extract_node('''
... def my_func(arg):
...     return arg + 1
... ''')
>>> node
<FunctionDef.my_func l.2 at 0x7f23b2e71e10>
Parameters
  • name (str or None) – The name of the function.

  • doc (str or None) – The function’s docstring.

  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – Unused.

Returns

The range of line numbers that this node belongs to,

Return type

tuple(int, int)

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a FunctionDef this is always True.

Return type

bool

decoratornames(context=None)[source]

Get the qualified names of each of the decorators on this function.

Parameters

context – An inference context that can be passed to inference functions

Returns

The names of the decorators.

Return type

set(str)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

getattr(name, context=None)[source]

this method doesn’t look in the instance_attrs dictionary since it’s done by an Instance proxy at inference time.

igetattr(name, context=None)[source]

Inferred getattr, which returns an iterator of inferred statements.

infer_call_result(caller=None, context=None)[source]

Infer what the function returns when called.

Returns

What the function returns.

Return type

iterable(NodeNG or Uninferable) or None

is_abstract(pass_is_abstract=True, any_raise_is_abstract=False)[source]

Check if the method is abstract.

A method is considered abstract if any of the following is true: * The only statement is ‘raise NotImplementedError’ * The only statement is ‘raise <SomeException>’ and any_raise_is_abstract is True * The only statement is ‘pass’ and pass_is_abstract is True * The method is annotated with abc.astractproperty/abc.abstractmethod

Returns

True if the method is abstract, False otherwise.

Return type

bool

is_bound()[source]

Check if the function is bound to an instance or class.

Returns

True if the function is bound to an instance or class, False otherwise.

Return type

bool

is_generator()[source]

Check if this is a generator function.

Returns

True is this is a generator function, False otherwise.

Return type

bool

is_method()[source]

Check if this function node represents a method.

Returns

True if this is a method, False otherwise.

Return type

bool

postinit(args, body, decorators=None, returns=None, type_comment_returns=None, type_comment_args=None)[source]

Do some setup after initialisation.

Parameters
  • args (Arguments or list) – The arguments that the function takes.

  • body (list(NodeNG)) – The contents of the function body.

  • decorators (Decorators or None) – The decorators that are applied to this method or function.

Params type_comment_returns

The return type annotation passed via a type comment.

Params type_comment_args

The args type annotation passed via a type comment.

scope_lookup(node, name, offset=0)[source]

Lookup where the given name is assigned.

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

decorators = None

The decorators that are applied to this method or function.

Type

Decorators or None

doc

The function’s docstring.

extra_decorators

<wrapped by the cachedproperty decorator> The extra decorators that this function can have.

Additional decorators are considered when they are used as assignments, as in method = staticmethod(method). The property will return all the callables that are used for decoration.

type

list(NodeNG)

fromlineno

<wrapped by the cachedproperty decorator> The first line that this node appears on in the source code.

type

int or None

is_function: ClassVar[bool] = True

Whether this node indicates a function.

For a FunctionDef this is always True.

Type

bool

returns = None
special_attributes

The names of special attributes that this function has.

Type

objectmodel.FunctionModel

type

<wrapped by the cachedproperty decorator> The function type for this node.

Possible values are: method, function, staticmethod, classmethod.

type

str

type_annotation = None

If present, this will contain the type annotation passed by a type comment

Type

NodeNG or None

type_comment_args = None

If present, this will contain the type annotation for arguments passed by a type comment

type_comment_returns = None

If present, this will contain the return type annotation, passed by a type comment

class astroid.nodes.GeneratorExp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes.ComprehensionScope

Class representing an ast.GeneratorExp node.

>>> node = astroid.extract_node('(thing for thing in things if thing)')
>>> node
<GeneratorExp l.1 at 0x7f23b2e4e400>
Parameters
  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a GeneratorExp this is always True.

Return type

bool

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(elt=None, generators=None)[source]

Do some setup after initialisation.

Parameters
  • elt (NodeNG or None) – The element that forms the output of the expression.

  • generators (list(Comprehension) or None) – The generators that are looped through.

elt = None

The element that forms the output of the expression.

Type

NodeNG or None

generators = None

The generators that are looped through.

Type

list(Comprehension) or None

class astroid.nodes.Global(names, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Global node.

>>> node = astroid.extract_node('global a_global')
>>> node
<Global l.1 at 0x7f23b2e9de10>
Parameters
  • names (List[str]) – The names being declared as global.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

names: List[str]

The names being declared as global.

class astroid.nodes.If(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.node_classes.Statement

Class representing an ast.If node.

>>> node = astroid.extract_node('if condition: print(True)')
>>> node
<If l.1 at 0x7f23b2e9dd30>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

has_elif_block()[source]
postinit(test=None, body=None, orelse=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the block.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block.

test: Optional[astroid.node_classes.NodeNG]

The condition that the statement tests.

class astroid.nodes.IfExp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.IfExp node.

>>> node = astroid.extract_node('value if condition else other')
>>> node
<IfExp l.1 at 0x7f23b2e9dbe0>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

op_left_associative()[source]
postinit(test=None, body=None, orelse=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

body: Optional[astroid.node_classes.NodeNG]

The contents of the block.

orelse: Optional[astroid.node_classes.NodeNG]

The contents of the else block.

test: Optional[astroid.node_classes.NodeNG]

The condition that the statement tests.

class astroid.nodes.Import(names=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.mixins.ImportFromMixin, astroid.node_classes.Statement

Class representing an ast.Import node.

>>> node = astroid.extract_node('import astroid')
>>> node
<Import l.1 at 0x7f23b2e4e5c0>
Parameters
  • names (Optional[List[Tuple[str, Optional[str]]]]) – The names being imported.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

names: List[Tuple[str, Optional[str]]]

The names being imported.

Each entry is a tuple of the name being imported, and the alias that the name is assigned to (if any).

class astroid.nodes.ImportFrom(fromname, names, level=0, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.mixins.ImportFromMixin, astroid.node_classes.Statement

Class representing an ast.ImportFrom node.

>>> node = astroid.extract_node('from my_package import my_module')
>>> node
<ImportFrom l.1 at 0x7f23b2e415c0>
Parameters
  • fromname (Optional[str]) – The module that is being imported from.

  • names (List[Tuple[str, Optional[str]]]) – What is being imported from the module.

  • level (Optional[int]) – The level of relative import.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

level: Optional[int]

The level of relative import.

Essentially this is the number of dots in the import. This is always 0 for absolute imports.

modname: Optional[str]

The module that is being imported from.

This is None for relative imports.

names: List[Tuple[str, Optional[str]]]

What is being imported from the module.

Each entry is a tuple of the name being imported, and the alias that the name is assigned to (if any).

class astroid.nodes.Index(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Index node.

An Index is a simple subscript.

Deprecated since v2.6.0 - Now part of the Subscript node. Will be removed with the release of v2.7.0

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

class astroid.nodes.JoinedStr(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Represents a list of string expressions to be joined.

>>> node = astroid.extract_node('f"Format {type_}"')
>>> node
<JoinedStr l.1 at 0x7f23b2e4ed30>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(values=None)[source]

Do some setup after initialisation.

Parameters
Type

list(FormattedValue or Const)

Return type

None

values: List[astroid.node_classes.NodeNG]

The string expressions to be joined.

Type

list(FormattedValue or Const)

class astroid.nodes.Keyword(arg=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.keyword node.

>>> node = astroid.extract_node('function(a_kwarg=True)')
>>> node
<Call l.1 at 0x7f23b2e9e320>
>>> node.keywords
[<Keyword l.1 at 0x7f23b2e9e9b0>]
Parameters
  • arg (Optional[str]) – The argument being assigned to.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – The value being assigned to the ketword argument.

Return type

None

arg: Optional[str]

The argument being assigned to.

value: Optional[astroid.node_classes.NodeNG]

The value being assigned to the keyword argument.

class astroid.nodes.Lambda(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.FilterStmtsMixin, astroid.scoped_nodes.LocalsDictNodeNG

Class representing an ast.Lambda node.

>>> node = astroid.extract_node('lambda arg: arg + 1')
>>> node
<Lambda.<lambda> l.1 at 0x7f23b2e41518>
Parameters
  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

argnames()[source]

Get the names of each of the arguments.

Returns

The names of the arguments.

Return type

list(str)

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a Lambda this is always True.

Return type

bool

callable()[source]

Whether this node defines something that is callable.

Returns

True if this defines something that is callable, False otherwise. For a Lambda this is always True.

Return type

bool

display_type()[source]

A human readable type of this node.

Returns

The type of this node.

Return type

str

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

implicit_parameters()[source]
infer_call_result(caller, context=None)[source]

Infer what the function returns when called.

Parameters

caller (object) – Unused

postinit(args, body)[source]

Do some setup after initialisation.

Parameters
  • args (Arguments) – The arguments that the function takes.

  • body (list(NodeNG)) – The contents of the function body.

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

scope_lookup(node, name, offset=0)[source]

Lookup where the given names is assigned.

Parameters
  • node (NodeNG) – The node to look for assignments up to. Any assignments after the given node are ignored.

  • name (str) – The name to find assignments for.

  • offset (int) – The line offset to filter statements up to.

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

Return type

tuple(str, list(NodeNG))

args

The arguments that the function takes.

Type

Arguments or list

body

The contents of the function body.

Type

list(NodeNG)

is_lambda: ClassVar[bool] = True
name = '<lambda>'
property type

Whether this is a method or function.

Returns

‘method’ if this is a method, ‘function’ otherwise.

Return type

str

class astroid.nodes.List(ctx=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes._BaseContainer

Class representing an ast.List node.

>>> node = astroid.extract_node('[1, 2, 3]')
>>> node
<List.list l.1 at 0x7f23b2e9e128>
Parameters
  • ctx (Optional[astroid.const.Context]) – Whether the list is assigned to or loaded from.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
getitem(index, context=None)[source]

Get an item from this node.

Parameters

index (Const or Slice) – The node to use as a subscript index.

infer_binary_op(opnode, operator, other, context, method)
infer_unary_op(op)
pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

ctx: Optional[astroid.const.Context]

Whether the list is assigned to or loaded from.

class astroid.nodes.ListComp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes._ListComp, astroid.scoped_nodes.ComprehensionScope

Class representing an ast.ListComp node.

>>> node = astroid.extract_node('[thing for thing in things if thing]')
>>> node
<ListComp l.1 at 0x7f23b2e418d0>
Parameters
  • lineno – The line that this node appears on in the source code.

  • col_offset – The column that this node appears on in the source code.

  • parent – The parent node in the syntax tree.

class astroid.nodes.Match(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing a ast.Match node.

>>> node = astroid.extract_node('''
match x:
    case 200:
        ...
    case _:
        ...
''')
>>> node
<Match l.2 at 0x10c24e170>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, subject, cases)[source]
Parameters
Return type

None

class astroid.nodes.MatchAs(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Pattern

Class representing a ast.MatchAs node.

>>> node = astroid.extract_node('''
match x:
    case [1, a]:
        ...
    case {'key': b}:
        ...
    case Point2D(0, 0) as c:
        ...
    case d:
        ...
''')
>>> node.cases[0].pattern.patterns[1]
<MatchAs l.3 at 0x10d0b2da0>
>>> node.cases[1].pattern.patterns[0]
<MatchAs l.5 at 0x10d0b2920>
>>> node.cases[2].pattern
<MatchAs l.7 at 0x10d0b06a0>
>>> node.cases[3].pattern
<MatchAs l.9 at 0x10d09b880>
Parameters
Return type

None

postinit(*, pattern, name)[source]
Parameters
Return type

None

class astroid.nodes.MatchCase(*, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.node_classes.NodeNG

Class representing a ast.match_case node.

>>> node = astroid.extract_node('''
match x:
    case 200:
        ...
''')
>>> node.cases[0]
<MatchCase l.3 at 0x10c24e590>
Parameters

parent (Optional[astroid.node_classes.NodeNG]) –

Return type

None

postinit(*, pattern, guard, body)[source]
Parameters
Return type

None

class astroid.nodes.MatchClass(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchClass node.

>>> node = astroid.extract_node('''
match x:
    case Point2D(0, 0):
        ...
    case Point3D(x=0, y=0, z=0):
        ...
''')
>>> node.cases[0].pattern
<MatchClass l.3 at 0x10ca83940>
>>> node.cases[1].pattern
<MatchClass l.5 at 0x10ca80880>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, cls, patterns, kwd_attrs, kwd_patterns)[source]
Parameters
Return type

None

class astroid.nodes.MatchMapping(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Pattern

Class representing a ast.MatchMapping node.

>>> node = astroid.extract_node('''
match x:
    case {1: "Hello", 2: "World", 3: _, **rest}:
        ...
''')
>>> node.cases[0].pattern
<MatchMapping l.3 at 0x10c8a8850>
Parameters
Return type

None

postinit(*, keys, patterns, rest)[source]
Parameters
Return type

None

class astroid.nodes.MatchOr(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchOr node.

>>> node = astroid.extract_node('''
match x:
    case 400 | 401 | 402:
        ...
''')
>>> node.cases[0].pattern
<MatchOr l.3 at 0x10d0b0b50>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, patterns)[source]
Parameters

patterns (List[astroid.node_classes.Pattern]) –

Return type

None

class astroid.nodes.MatchSequence(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchSequence node.

>>> node = astroid.extract_node('''
match x:
    case [1, 2]:
        ...
    case (1, 2, *_):
        ...
''')
>>> node.cases[0].pattern
<MatchSequence l.3 at 0x10ca80d00>
>>> node.cases[1].pattern
<MatchSequence l.5 at 0x10ca80b20>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, patterns)[source]
Parameters

patterns (List[astroid.node_classes.Pattern]) –

Return type

None

class astroid.nodes.MatchSingleton(*, value, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchSingleton node.

>>> node = astroid.extract_node('''
match x:
    case True:
        ...
    case False:
        ...
    case None:
        ...
''')
>>> node.cases[0].pattern
<MatchSingleton l.3 at 0x10c2282e0>
>>> node.cases[1].pattern
<MatchSingleton l.5 at 0x10c228af0>
>>> node.cases[2].pattern
<MatchSingleton l.7 at 0x10c229f90>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

  • value (typing_extensions.Literal[True, False, None]) –

Return type

None

class astroid.nodes.MatchStar(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Pattern

Class representing a ast.MatchStar node.

>>> node = astroid.extract_node('''
match x:
    case [1, *_]:
        ...
''')
>>> node.cases[0].pattern.patterns[1]
<MatchStar l.3 at 0x10ca809a0>
Parameters
Return type

None

postinit(*, name)[source]
Parameters

name (Optional[astroid.node_classes.AssignName]) –

Return type

None

class astroid.nodes.MatchValue(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchValue node.

>>> node = astroid.extract_node('''
match x:
    case 200:
        ...
''')
>>> node.cases[0].pattern
<MatchValue l.3 at 0x10c24e200>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, value)[source]
Parameters

value (astroid.node_classes.NodeNG) –

Return type

None

class astroid.nodes.Module(name, doc, file=None, path=None, package=None, parent=None, pure_python=True)[source]

Bases: astroid.scoped_nodes.LocalsDictNodeNG

Class representing an ast.Module node.

>>> node = astroid.extract_node('import astroid')
>>> node
<Import l.1 at 0x7f23b2e4e5c0>
>>> node.parent
<Module l.0 at 0x7f23b2e4eda0>
Parameters
  • name (str) – The name of the module.

  • doc (str) – The module docstring.

  • file (str or None) – The path to the file that this ast has been extracted from.

  • path (Optional[List[str]]) –

  • package (bool or None) – Whether the node represents a package or a module.

  • parent (NodeNG or None) – The parent node in the syntax tree.

  • pure_python (bool or None) – Whether the ast was built from source.

absolute_import_activated()[source]

Whether PEP 328 absolute import behaviour has been enabled.

Returns

True if PEP 328 has been enabled, False otherwise.

Return type

bool

block_range(lineno)[source]

Get a range from where this node starts to where this node ends.

Parameters

lineno (int) – Unused.

Returns

The range of line numbers that this node belongs to.

Return type

tuple(int, int)

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a Module this is always True.

Return type

bool

display_type()[source]

A human readable type of this node.

Returns

The type of this node.

Return type

str

fully_defined()[source]

Check if this module has been build from a .py file.

If so, the module contains a complete representation, including the code.

Returns

True if the module has been built from a .py file.

Return type

bool

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

getattr(name, context=None, ignore_locals=False)[source]
igetattr(name, context=None)[source]

Infer the possible values of the given variable.

Parameters

name (str) – The name of the variable to infer.

Returns

The inferred possible values.

Return type

iterable(NodeNG) or None

import_module(modname, relative_only=False, level=None)[source]

Get the ast for a given module as if imported from this module.

Parameters
  • modname (str) – The name of the module to “import”.

  • relative_only (bool) – Whether to only consider relative imports.

  • level (int or None) – The level of relative import.

Returns

The imported module ast.

Return type

NodeNG

next_sibling()[source]

The next sibling statement node.

Returns

The next sibling statement node.

Return type

NodeNG or None

postinit(body=None)[source]

Do some setup after initialisation.

Parameters

body (list(NodeNG) or None) – The contents of the module.

previous_sibling()[source]

The previous sibling statement.

Returns

The previous sibling statement node.

Return type

NodeNG or None

public_names()[source]

The list of the names that are publicly available in this module.

Returns

The list of publc names.

Return type

list(str)

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

relative_to_absolute_name(modname, level)[source]

Get the absolute module name for a relative import.

The relative import can be implicit or explicit.

Parameters
  • modname (str) – The module name to convert.

  • level (int) – The level of relative import.

Returns

The absolute module name.

Return type

str

Raises

TooManyLevelsError – When the relative import refers to a module too far above this one.

scope_lookup(node, name, offset=0)[source]

Lookup where the given variable is assigned.

Parameters
  • node (NodeNG) – The node to look for assignments up to. Any assignments after the given node are ignored.

  • name (str) – The name of the variable to find assignments for.

  • offset (int) – The line offset to filter statements up to.

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

Return type

tuple(str, list(NodeNG))

statement()[source]

The first parent node, including self, marked as statement node.

Returns

The first parent statement.

Return type

NodeNG

stream()[source]

Get a stream to the underlying file or bytes.

Type

file or io.BytesIO or None

wildcard_import_names()[source]

The list of imported names when this module is ‘wildcard imported’.

It doesn’t include the ‘__builtins__’ name which is added by the current CPython implementation of wildcard imports.

Returns

The list of imported names.

Return type

list(str)

body

The contents of the module.

Type

list(NodeNG) or None

file = None

The path to the file that this ast has been extracted from.

This will be None when the representation has been built from a built-in module.

Type

str or None

file_bytes = None

The string/bytes that this ast was built from.

Type

str or bytes or None

file_encoding = None

The encoding of the source file.

This is used to get unicode out of a source file. Python 2 only.

Type

str or None

fromlineno = 0

The first line that this node appears on in the source code.

Type

int or None

future_imports = None

The imports from __future__.

Type

set(str) or None

globals = None

A map of the name of a global variable to the node defining the global.

Type

dict(str, NodeNG)

lineno: Optional[int] = 0

The line that this node appears on in the source code.

Type

int or None

name = None

The name of the module.

Type

str or None

package = None

Whether the node represents a package or a module.

Type

bool or None

pure_python = None

Whether the ast was built from source.

Type

bool or None

scope_attrs = {'__doc__', '__file__', '__name__', '__package__', '__path__'}

The names of module attributes available through the global scope.

Type

str(str)

special_attributes

The names of special attributes that this module has.

Type

objectmodel.ModuleModel

class astroid.nodes.Name(name=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.LookupMixIn, astroid.node_classes.NodeNG

Class representing an ast.Name node.

A Name node is something that is named, but not covered by AssignName or DelName.

>>> node = astroid.extract_node('range(10)')
>>> node
<Call l.1 at 0x7effe1db8710>
>>> list(node.get_children())
[<Name.range l.1 at 0x7effe1db86a0>, <Const.int l.1 at 0x7effe1db8518>]
>>> list(node.get_children())[0].as_string()
'range'
Parameters
  • name (Optional[str]) – The name that this node refers to.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

name: Optional[str]

The name that this node refers to.

class astroid.nodes.NamedExpr(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.NodeNG

Represents the assignment from the assignment expression

>>> module = astroid.parse('if a := 1: pass')
>>> module.body[0].test
<NamedExpr l.1 at 0x7f23b2e4ed30>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[astroid.node_classes.NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node, context=None, assign_path=None)

Infer names and other nodes from an assignment expression

postinit(target, value)[source]
Parameters
Return type

None

target: astroid.node_classes.NodeNG

The assignment target

Type

Name

value: astroid.node_classes.NodeNG

The value that gets assigned in the expression

class astroid.nodes.NodeNG(lineno=None, col_offset=None, parent=None)[source]

Bases: object

A node of the new Abstract Syntax Tree (AST).

This is the base class for all Astroid node classes.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

accept(visitor)[source]

Visit this node using the given visitor.

as_string()[source]

Get the source code that this node represents.

Returns

The source code.

Return type

str

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int or None)

bool_value(context=None)[source]

Determine the boolean value of this node.

The boolean value of a node can have three possible values:

  • False: For instance, empty data structures, False, empty strings, instances which return explicitly False from the __nonzero__ / __bool__ method.

  • True: Most of constructs are True by default: classes, functions, modules etc

  • Uninferable: The inference engine is uncertain of the node’s value.

Returns

The boolean value of this node.

Return type

bool or Uninferable

callable()[source]

Whether this node defines something that is callable.

Returns

True if this defines something that is callable, False otherwise.

Return type

bool

child_sequence(child)[source]

Search for the sequence that contains this child.

Parameters

child (NodeNG) – The child node to search sequences for.

Returns

The sequence containing the given child node.

Return type

iterable(NodeNG)

Raises

AstroidError – If no sequence could be found that contains the given child.

eq(value)[source]
frame()[source]

The first parent frame node.

A frame node is a Module, FunctionDef, or ClassDef.

Returns

The first parent frame node.

Return type

Module or FunctionDef or ClassDef

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

has_base(node)[source]

Check if this node inherits from the given type.

Parameters

node (NodeNG) – The node defining the base to look for. Usually this is a Name node.

infer(context=None, **kwargs)[source]

Get a generator of the inferred values.

This is the main entry point to the inference system.

If the instance has some explicit inference function set, it will be called instead of the default interface.

Returns

The inferred values.

Return type

iterable

inferred()[source]

Get a list of the inferred values.

Returns

The inferred values.

Return type

list

instantiate_class()[source]

Instantiate an instance of the defined class.

Note

On anything other than a ClassDef this will return self.

Returns

An instance of the defined class.

Return type

object

last_child()[source]

An optimized version of list(get_children())[-1]

locate_child(child)[source]

Find the field of this node that contains the given child.

Parameters

child (NodeNG) – The child node to search fields for.

Returns

A tuple of the name of the field that contains the child, and the sequence or node that contains the child node.

Return type

tuple(str, iterable(NodeNG) or NodeNG)

Raises

AstroidError – If no field could be found that contains the given child.

next_sibling()[source]

The next sibling statement node.

Returns

The next sibling statement node.

Return type

NodeNG or None

nodes_of_class(klass, skip_klass=None)[source]

Get the nodes (including this one or below) of the given types.

Parameters
  • klass (builtins.type or tuple(builtins.type)) – The types of node to search for.

  • skip_klass (builtins.type or tuple(builtins.type)) – The types of node to ignore. This is useful to ignore subclasses of klass.

Returns

The node of the given types.

Return type

iterable(NodeNG)

op_left_associative()[source]
op_precedence()[source]
parent_of(node)[source]

Check if this node is the parent of the given node.

Parameters

node (NodeNG) – The node to check if it is the child.

Returns

True if this node is the parent of the given node, False otherwise.

Return type

bool

previous_sibling()[source]

The previous sibling statement.

Returns

The previous sibling statement node.

Return type

NodeNG or None

repr_tree(ids=False, include_linenos=False, ast_state=False, indent='   ', max_depth=0, max_width=80)[source]

Get a string representation of the AST from this node.

Parameters
  • ids (bool) – If true, includes the ids with the node type names.

  • include_linenos (bool) – If true, includes the line numbers and column offsets.

  • ast_state (bool) – If true, includes information derived from the whole AST like local and global variables.

  • indent (str) – A string to use to indent the output string.

  • max_depth (int) – If set to a positive integer, won’t return nodes deeper than max_depth in the string.

  • max_width (int) – Attempt to format the output string to stay within this number of characters, but can exceed it under some circumstances. Only positive integer values are valid, the default is 80.

Returns

The string representation of the AST.

Return type

str

root()[source]

Return the root node of the syntax tree.

Returns

The root node.

Return type

Module

scope()[source]

The first parent node defining a new scope.

Returns

The first parent scope node.

Return type

Module or FunctionDef or ClassDef or Lambda or GenExpr

set_local(name, stmt)[source]

Define that the given name is declared in the given statement node.

This definition is stored on the parent scope node.

See also

scope()

Parameters
  • name (str) – The name that is being defined.

  • stmt (NodeNG) – The statement that defines the given name.

statement()[source]

The first parent node, including self, marked as statement node.

Returns

The first parent statement.

Return type

NodeNG

col_offset: Optional[int]

The column that this node appears on in the source code.

fromlineno

<wrapped by the cachedproperty decorator> The first line that this node appears on in the source code.

is_function: ClassVar[bool] = False

Whether this node indicates a function.

is_lambda: ClassVar[bool] = False
is_statement: ClassVar[bool] = False

Whether this node indicates a statement.

lineno: Optional[int]

The line that this node appears on in the source code.

optional_assign: ClassVar[bool] = False

Whether this node optionally assigns a variable.

This is for loop assignments because loop won’t necessarily perform an assignment if the loop has no iterations. This is also the case from comprehensions in Python 2.

parent: Optional[NodeNG]

The parent node in the syntax tree.

tolineno

<wrapped by the cachedproperty decorator> The last line that this node appears on in the source code.

class astroid.nodes.Nonlocal(names, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Nonlocal node.

>>> node = astroid.extract_node('''
def function():
    nonlocal var
''')
>>> node
<FunctionDef.function l.2 at 0x7f23b2e9e208>
>>> node.body[0]
<Nonlocal l.3 at 0x7f23b2e9e908>
Parameters
  • names (List[str]) – The names being declared as not local.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

names: List[str]

The names being declared as not local.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Pass(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Pass node.

>>> node = astroid.extract_node('pass')
>>> node
<Pass l.1 at 0x7f23b2e9e748>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Raise(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing an ast.Raise node.

>>> node = astroid.extract_node('raise RuntimeError("Something bad happened!")')
>>> node
<Raise l.1 at 0x7f23b2e9e828>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(exc=None, cause=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

raises_not_implemented()[source]

Check if this node raises a NotImplementedError.

Returns

True if this node raises a NotImplementedError, False otherwise.

Return type

bool

cause: Optional[astroid.node_classes.NodeNG]

The exception being used to raise this one.

col_offset: Optional[int]

The column that this node appears on in the source code.

exc: Optional[astroid.node_classes.NodeNG]

What is being raised.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Return(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing an ast.Return node.

>>> node = astroid.extract_node('return True')
>>> node
<Return l.1 at 0x7f23b8211908>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

is_tuple_return()[source]
postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – The value being returned.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

The value being returned.

class astroid.nodes.Set(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes._BaseContainer

Class representing an ast.Set node.

>>> node = astroid.extract_node('{1, 2, 3}')
>>> node
<Set.set l.1 at 0x7f23b2e71d68>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

infer_unary_op(op)
pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.SetComp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes.ComprehensionScope

Class representing an ast.SetComp node.

>>> node = astroid.extract_node('{thing for thing in things if thing}')
>>> node
<SetComp l.1 at 0x7f23b2e41898>
Parameters
  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a SetComp this is always Uninferable.

Return type

Uninferable

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(elt=None, generators=None)[source]

Do some setup after initialisation.

Parameters
  • elt (NodeNG or None) – The element that forms the output of the expression.

  • generators (list(Comprehension) or None) – The generators that are looped through.

col_offset: Optional[int]

The column that this node appears on in the source code.

elt = None

The element that forms the output of the expression.

Type

NodeNG or None

generators = None

The generators that are looped through.

Type

list(Comprehension) or None

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Slice(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Slice node.

>>> node = astroid.extract_node('things[1:3]')
>>> node
<Subscript l.1 at 0x7f23b2e71f60>
>>> node.slice
<Slice l.1 at 0x7f23b2e71e80>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

getattr(attrname, context=None)[source]
igetattr(attrname, context=None)[source]

Infer the possible values of the given attribute on the slice.

Parameters

attrname (str) – The name of the attribute to infer.

Returns

The inferred possible values.

Return type

iterable(NodeNG)

postinit(lower=None, upper=None, step=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

lower: Optional[astroid.node_classes.NodeNG]

The lower index in the slice.

parent: Optional[NodeNG]

The parent node in the syntax tree.

step: Optional[astroid.node_classes.NodeNG]

The step to take between indexes.

upper: Optional[astroid.node_classes.NodeNG]

The upper index in the slice.

class astroid.nodes.Starred(ctx=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Class representing an ast.Starred node.

>>> node = astroid.extract_node('*args')
>>> node
<Starred l.1 at 0x7f23b2e41978>
Parameters
  • ctx (Optional[astroid.const.Context]) – Whether the list is assigned to or loaded from.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
Parameters
  • self – nodes.Starred

  • node – a node related to the current underlying Node.

  • context – Inference context used for caching already inferred objects

  • assign_path – A list of indices, where each index specifies what item to fetch from the inference results.

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – What is being unpacked.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

ctx: Optional[astroid.const.Context]

Whether the starred item is assigned to or loaded from.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

What is being unpacked.

class astroid.nodes.Subscript(ctx=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Subscript node.

>>> node = astroid.extract_node('things[1:3]')
>>> node
<Subscript l.1 at 0x7f23b2e71f60>
Parameters
  • ctx (Optional[astroid.const.Context]) – Whether the subscripted item is assigned to or loaded from.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

infer_lhs(context=None)

Inference for subscripts

We’re understanding if the index is a Const or a slice, passing the result of inference to the value’s getitem method, which should handle each supported index type accordingly.

postinit(value=None, slice=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

ctx: Optional[astroid.const.Context]

Whether the subscripted item is assigned to or loaded from.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

slice: Optional[astroid.node_classes.NodeNG]

The slice being used to lookup.

value: Optional[astroid.node_classes.NodeNG]

What is being indexed.

class astroid.nodes.TryExcept(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.node_classes.Statement

Class representing an ast.TryExcept node.

>>> node = astroid.extract_node('''
    try:
        do_something()
    except Exception as error:
        print("Error!")
    ''')
>>> node
<TryExcept l.2 at 0x7f23b2e9d908>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(body=None, handlers=None, orelse=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

body: List[astroid.node_classes.NodeNG]

The contents of the block to catch exceptions from.

col_offset: Optional[int]

The column that this node appears on in the source code.

handlers: List[astroid.node_classes.ExceptHandler]

The exception handlers.

lineno: Optional[int]

The line that this node appears on in the source code.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.TryFinally(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.node_classes.Statement

Class representing an ast.TryFinally node.

>>> node = astroid.extract_node('''
try:
    do_something()
except Exception as error:
    print("Error!")
finally:
    print("Cleanup!")
''')
>>> node
<TryFinally l.2 at 0x7f23b2e41d68>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(body=None, finalbody=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

body: Union[List[astroid.node_classes.TryExcept], List[astroid.node_classes.NodeNG]]

The try-except that the finally is attached to.

col_offset: Optional[int]

The column that this node appears on in the source code.

finalbody: List[astroid.node_classes.NodeNG]

The contents of the finally block.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Tuple(ctx=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes._BaseContainer

Class representing an ast.Tuple node.

>>> node = astroid.extract_node('(1, 2, 3)')
>>> node
<Tuple.tuple l.1 at 0x7f23b2e41780>
Parameters
  • ctx (Optional[astroid.const.Context]) – Whether the tuple is assigned to or loaded from.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
getitem(index, context=None)[source]

Get an item from this node.

Parameters

index (Const or Slice) – The node to use as a subscript index.

infer_binary_op(opnode, operator, other, context, method)
infer_unary_op(op)
pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

ctx: Optional[astroid.const.Context]

Whether the tuple is assigned to or loaded from.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.UnaryOp(op=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.UnaryOp node.

>>> node = astroid.extract_node('-5')
>>> node
<UnaryOp l.1 at 0x7f23b2e4e198>
Parameters
  • op (Optional[str]) – The operator.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

op_precedence()[source]
postinit(operand=None)[source]

Do some setup after initialisation.

Parameters

operand (Optional[astroid.node_classes.NodeNG]) – What the unary operator is applied to.

Return type

None

type_errors(context=None)[source]

Get a list of type errors which can occur during inference.

Each TypeError is represented by a BadBinaryOperationMessage, which holds the original exception.

Returns

The list of possible type errors.

Return type

list(BadBinaryOperationMessage)

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

op: Optional[str]

The operator.

operand: Optional[astroid.node_classes.NodeNG]

What the unary operator is applied to.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Unknown(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.NodeNG

This node represents a node in a constructed AST where introspection is not possible. At the moment, it’s only used in the args attribute of FunctionDef nodes where function signature introspection failed.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

infer(context=None, **kwargs)[source]

Inference on an Unknown node immediately terminates.

qname()[source]
col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

name = 'Unknown'
parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.While(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.node_classes.Statement

Class representing an ast.While node.

>>> node = astroid.extract_node('''
while condition():
    print("True")
''')
>>> node
<While l.2 at 0x7f23b2e4e390>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(test=None, body=None, orelse=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the loop.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block.

parent: Optional[NodeNG]

The parent node in the syntax tree.

test: Optional[astroid.node_classes.NodeNG]

The condition that the loop tests.

class astroid.nodes.With(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.With node.

>>> node = astroid.extract_node('''
with open(file_path) as file_:
    print(file_.read())
''')
>>> node
<With l.2 at 0x7f23b2e4e710>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)

Infer names and other nodes from a with statement.

This enables only inference for name binding in a with statement. For instance, in the following code, inferring func will return the ContextManager class, not whatever __enter__ returns. We are doing this intentionally, because we consider that the context manager result is whatever __enter__ returns and what it is binded using the as keyword.

class ContextManager(object):
def __enter__(self):

return 42

with ContextManager() as f:

pass

# ContextManager().infer() will return ContextManager # f.infer() will return 42.

Parameters
  • self – nodes.With

  • node – The target of the assignment, as (a, b) in with foo as (a, b).

  • context – Inference context used for caching already inferred objects

  • assign_path – A list of indices, where each index specifies what item to fetch from the inference results.

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(items=None, body=None, type_annotation=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the with block.

col_offset: Optional[int]

The column that this node appears on in the source code.

items: List[Tuple[astroid.node_classes.NodeNG, Optional[astroid.node_classes.NodeNG]]]

The pairs of context managers and the names they are assigned to.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

type_annotation: Optional[astroid.node_classes.NodeNG]

If present, this will contain the type annotation passed by a type comment

class astroid.nodes.Yield(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Yield node.

>>> node = astroid.extract_node('yield True')
>>> node
<Yield l.1 at 0x7f23b2e4e5f8>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – The value to yield.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

The value to yield.

class astroid.nodes.YieldFrom(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Yield

Class representing an ast.YieldFrom node.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

The value to yield.

astroid.nodes.const_factory(value)[source]

return an astroid node for a python value

For a list of available nodes see Nodes.

Nodes

AnnAssign([lineno, col_offset, parent])

Class representing an ast.AnnAssign node.

Arguments([vararg, kwarg, parent])

Class representing an ast.arguments node.

Assert([lineno, col_offset, parent])

Class representing an ast.Assert node.

Assign([lineno, col_offset, parent])

Class representing an ast.Assign node.

AssignAttr([attrname, lineno, col_offset, …])

Variation of ast.Assign representing assignment to an attribute.

AssignName([name, lineno, col_offset, parent])

Variation of ast.Assign representing assignment to a name.

AsyncFor([lineno, col_offset, parent])

Class representing an ast.AsyncFor node.

AsyncFunctionDef([name, doc, lineno, …])

Class representing an ast.FunctionDef node.

AsyncWith([lineno, col_offset, parent])

Asynchronous with built with the async keyword.

Attribute([attrname, lineno, col_offset, parent])

Class representing an ast.Attribute node.

AugAssign([op, lineno, col_offset, parent])

Class representing an ast.AugAssign node.

Await([lineno, col_offset, parent])

Class representing an ast.Await node.

BinOp([op, lineno, col_offset, parent])

Class representing an ast.BinOp node.

BoolOp([op, lineno, col_offset, parent])

Class representing an ast.BoolOp node.

Break([lineno, col_offset, parent])

Class representing an ast.Break node.

Call([lineno, col_offset, parent])

Class representing an ast.Call node.

ClassDef([name, doc, lineno, col_offset, parent])

Class representing an ast.ClassDef node.

Compare([lineno, col_offset, parent])

Class representing an ast.Compare node.

Comprehension([parent])

Class representing an ast.comprehension node.

Const(value[, lineno, col_offset, parent, kind])

Class representing any constant including num, str, bool, None, bytes.

Continue([lineno, col_offset, parent])

Class representing an ast.Continue node.

Decorators([lineno, col_offset, parent])

A node representing a list of decorators.

DelAttr([attrname, lineno, col_offset, parent])

Variation of ast.Delete representing deletion of an attribute.

DelName([name, lineno, col_offset, parent])

Variation of ast.Delete representing deletion of a name.

Delete([lineno, col_offset, parent])

Class representing an ast.Delete node.

Dict([lineno, col_offset, parent])

Class representing an ast.Dict node.

DictComp([lineno, col_offset, parent])

Class representing an ast.DictComp node.

DictUnpack([lineno, col_offset, parent])

Represents the unpacking of dicts into dicts using PEP 448.

Ellipsis([lineno, col_offset, parent])

Class representing an ast.Ellipsis node.

EmptyNode([lineno, col_offset, parent])

Holds an arbitrary object in the LocalsDictNodeNG.locals.

ExceptHandler([lineno, col_offset, parent])

Class representing an ast.ExceptHandler.

Expr([lineno, col_offset, parent])

Class representing an ast.Expr node.

ExtSlice([lineno, col_offset, parent])

Class representing an ast.ExtSlice node.

For([lineno, col_offset, parent])

Class representing an ast.For node.

FormattedValue([lineno, col_offset, parent])

Class representing an ast.FormattedValue node.

FunctionDef([name, doc, lineno, col_offset, …])

Class representing an ast.FunctionDef.

GeneratorExp([lineno, col_offset, parent])

Class representing an ast.GeneratorExp node.

Global(names[, lineno, col_offset, parent])

Class representing an ast.Global node.

If([lineno, col_offset, parent])

Class representing an ast.If node.

IfExp([lineno, col_offset, parent])

Class representing an ast.IfExp node.

Import([names, lineno, col_offset, parent])

Class representing an ast.Import node.

ImportFrom(fromname, names[, level, lineno, …])

Class representing an ast.ImportFrom node.

Index([lineno, col_offset, parent])

Class representing an ast.Index node.

JoinedStr([lineno, col_offset, parent])

Represents a list of string expressions to be joined.

Keyword([arg, lineno, col_offset, parent])

Class representing an ast.keyword node.

Lambda([lineno, col_offset, parent])

Class representing an ast.Lambda node.

List([ctx, lineno, col_offset, parent])

Class representing an ast.List node.

ListComp([lineno, col_offset, parent])

Class representing an ast.ListComp node.

Match([lineno, col_offset, parent])

Class representing a ast.Match node.

MatchAs([lineno, col_offset, parent])

Class representing a ast.MatchAs node.

MatchCase(*[, parent])

Class representing a ast.match_case node.

MatchClass([lineno, col_offset, parent])

Class representing a ast.MatchClass node.

MatchMapping([lineno, col_offset, parent])

Class representing a ast.MatchMapping node.

MatchOr([lineno, col_offset, parent])

Class representing a ast.MatchOr node.

MatchSequence([lineno, col_offset, parent])

Class representing a ast.MatchSequence node.

MatchSingleton(*, value[, lineno, …])

Class representing a ast.MatchSingleton node.

MatchStar([lineno, col_offset, parent])

Class representing a ast.MatchStar node.

MatchValue([lineno, col_offset, parent])

Class representing a ast.MatchValue node.

Module(name, doc[, file, path, package, …])

Class representing an ast.Module node.

Name([name, lineno, col_offset, parent])

Class representing an ast.Name node.

Nonlocal(names[, lineno, col_offset, parent])

Class representing an ast.Nonlocal node.

Pass([lineno, col_offset, parent])

Class representing an ast.Pass node.

Raise([lineno, col_offset, parent])

Class representing an ast.Raise node.

Return([lineno, col_offset, parent])

Class representing an ast.Return node.

Set([lineno, col_offset, parent])

Class representing an ast.Set node.

SetComp([lineno, col_offset, parent])

Class representing an ast.SetComp node.

Slice([lineno, col_offset, parent])

Class representing an ast.Slice node.

Starred([ctx, lineno, col_offset, parent])

Class representing an ast.Starred node.

Subscript([ctx, lineno, col_offset, parent])

Class representing an ast.Subscript node.

TryExcept([lineno, col_offset, parent])

Class representing an ast.TryExcept node.

TryFinally([lineno, col_offset, parent])

Class representing an ast.TryFinally node.

Tuple([ctx, lineno, col_offset, parent])

Class representing an ast.Tuple node.

UnaryOp([op, lineno, col_offset, parent])

Class representing an ast.UnaryOp node.

Unknown([lineno, col_offset, parent])

This node represents a node in a constructed AST where introspection is not possible.

While([lineno, col_offset, parent])

Class representing an ast.While node.

With([lineno, col_offset, parent])

Class representing an ast.With node.

Yield([lineno, col_offset, parent])

Class representing an ast.Yield node.

YieldFrom([lineno, col_offset, parent])

Class representing an ast.YieldFrom node.

class astroid.nodes.AnnAssign(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.AnnAssign node.

An AnnAssign is an assignment with a type annotation.

>>> node = astroid.extract_node('variable: List[int] = range(10)')
>>> node
<AnnAssign l.1 at 0x7effe1d4c630>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(target, annotation, simple, value=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

annotation: Optional[astroid.node_classes.NodeNG]

The type annotation of what is being assigned to.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

simple: Optional[int]

Whether target is a pure name or a complex statement.

target: Optional[astroid.node_classes.NodeNG]

What is being assigned to.

value: Optional[astroid.node_classes.NodeNG]

The value being assigned to the variables.

class astroid.nodes.Arguments(vararg=None, kwarg=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.NodeNG

Class representing an ast.arguments node.

An Arguments node represents that arguments in a function definition.

>>> node = astroid.extract_node('def foo(bar): pass')
>>> node
<FunctionDef.foo l.1 at 0x7effe1db8198>
>>> node.args
<Arguments l.1 at 0x7effe1db82e8>
Parameters
  • vararg (Optional[str]) – The name of the variable length arguments.

  • kwarg (Optional[str]) – The name of the variable length keyword arguments.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
default_value(argname)[source]

Get the default value for an argument.

Parameters

argname (str) – The name of the argument to get the default value for.

Raises

NoDefault – If there is no default value defined for the given argument.

find_argname(argname, rec=False)[source]

Get the index and AssignName node for given name.

Parameters
  • argname (str) – The name of the argument to search for.

  • rec (bool) – Whether or not to include arguments in unpacked tuples in the search.

Returns

The index and node for the argument.

Return type

tuple(str or None, AssignName or None)

format_args()[source]

Get the arguments formatted as string.

Returns

The formatted arguments.

Return type

str

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

is_argument(name)[source]

Check if the given name is defined in the arguments.

Parameters

name (str) – The name to check for.

Returns

True if the given name is defined in the arguments, False otherwise.

Return type

bool

postinit(args, defaults, kwonlyargs, kw_defaults, annotations, posonlyargs=None, kwonlyargs_annotations=None, posonlyargs_annotations=None, varargannotation=None, kwargannotation=None, type_comment_args=None, type_comment_kwonlyargs=None, type_comment_posonlyargs=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

annotations: List[Optional[astroid.node_classes.NodeNG]]

The type annotations of arguments that can be passed positionally.

args: List[astroid.node_classes.AssignName]

The names of the required arguments.

arguments

<wrapped by the cachedproperty decorator> Get all the arguments for this node, including positional only and positional and keyword

col_offset: Optional[int]

The column that this node appears on in the source code.

defaults: List[astroid.node_classes.NodeNG]

The default values for arguments that can be passed positionally.

fromlineno

<wrapped by the cachedproperty decorator> The first line that this node appears on in the source code.

type

int or None

kw_defaults: List[Optional[astroid.node_classes.NodeNG]]

The default values for keyword arguments that cannot be passed positionally.

kwarg: Optional[str]

The name of the variable length keyword arguments.

kwargannotation: Optional[astroid.node_classes.NodeNG]

The type annotation for the variable length keyword arguments.

kwonlyargs: List[astroid.node_classes.AssignName]

The keyword arguments that cannot be passed positionally.

kwonlyargs_annotations: List[Optional[astroid.node_classes.NodeNG]]

The type annotations of arguments that cannot be passed positionally.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

posonlyargs: List[astroid.node_classes.AssignName]

The arguments that can only be passed positionally.

posonlyargs_annotations: List[Optional[astroid.node_classes.NodeNG]]

The type annotations of arguments that can only be passed positionally.

type_comment_args: List[Optional[astroid.node_classes.NodeNG]]

The type annotation, passed by a type comment, of each argument.

If an argument does not have a type comment, the value for that argument will be None.

type_comment_kwonlyargs: List[Optional[astroid.node_classes.NodeNG]]

The type annotation, passed by a type comment, of each keyword only argument.

If an argument does not have a type comment, the value for that argument will be None.

type_comment_posonlyargs: List[Optional[astroid.node_classes.NodeNG]]

The type annotation, passed by a type comment, of each positional argument.

If an argument does not have a type comment, the value for that argument will be None.

vararg: Optional[str]

The name of the variable length arguments.

varargannotation: Optional[astroid.node_classes.NodeNG]

The type annotation for the variable length arguments.

class astroid.nodes.Assert(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing an ast.Assert node.

An Assert node represents an assert statement.

>>> node = astroid.extract_node('assert len(things) == 10, "Not enough things"')
>>> node
<Assert l.1 at 0x7effe1d527b8>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(test=None, fail=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

fail: Optional[astroid.node_classes.NodeNG]

The message shown when the assertion fails.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

test: Optional[astroid.node_classes.NodeNG]

The test that passes or fails the assertion.

class astroid.nodes.Assign(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.Assign node.

An Assign is a statement where something is explicitly asssigned to.

>>> node = astroid.extract_node('variable = range(10)')
>>> node
<Assign l.1 at 0x7effe1db8550>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(targets=None, value=None, type_annotation=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

targets: List[astroid.node_classes.NodeNG]

What is being assigned to.

type_annotation: Optional[astroid.node_classes.NodeNG]

If present, this will contain the type annotation passed by a type comment

value: Optional[astroid.node_classes.NodeNG]

The value being assigned to the variables.

class astroid.nodes.AssignAttr(attrname=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Variation of ast.Assign representing assignment to an attribute.

>>> node = astroid.extract_node('self.attribute = range(10)')
>>> node
<Assign l.1 at 0x7effe1d521d0>
>>> list(node.get_children())
[<AssignAttr.attribute l.1 at 0x7effe1d52320>, <Call l.1 at 0x7effe1d522e8>]
>>> list(node.get_children())[0].as_string()
'self.attribute'
Parameters
  • attrname (Optional[str]) – The name of the attribute being assigned to.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

infer_lhs(context=None)

infer an Attribute node by using getattr on the associated object

postinit(expr=None)[source]

Do some setup after initialisation.

Parameters

expr (Optional[astroid.node_classes.NodeNG]) – What has the attribute that is being assigned to.

Return type

None

attrname: Optional[str]

The name of the attribute being assigned to.

col_offset: Optional[int]

The column that this node appears on in the source code.

expr: Optional[astroid.node_classes.NodeNG]

What has the attribute that is being assigned to.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.AssignName(name=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.LookupMixIn, astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Variation of ast.Assign representing assignment to a name.

An AssignName is the name of something that is assigned to. This includes variables defined in a function signature or in a loop.

>>> node = astroid.extract_node('variable = range(10)')
>>> node
<Assign l.1 at 0x7effe1db8550>
>>> list(node.get_children())
[<AssignName.variable l.1 at 0x7effe1db8748>, <Call l.1 at 0x7effe1db8630>]
>>> list(node.get_children())[0].as_string()
'variable'
Parameters
  • name (Optional[str]) – The name that is assigned to.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
infer_lhs(context=None)

infer a Name: use name lookup rules

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

name: Optional[str]

The name that is assigned to.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.AsyncFor(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.For

Class representing an ast.AsyncFor node.

An AsyncFor is an asynchronous For built with the async keyword.

>>> node = astroid.extract_node('''
async def func(things):
    async for thing in things:
        print(thing)
''')
>>> node
<AsyncFunctionDef.func l.2 at 0x7f23b2e416d8>
>>> node.body[0]
<AsyncFor l.3 at 0x7f23b2e417b8>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

body: List[astroid.node_classes.NodeNG]

The contents of the body of the loop.

col_offset: Optional[int]

The column that this node appears on in the source code.

iter: Optional[astroid.node_classes.NodeNG]

What the loop iterates over.

lineno: Optional[int]

The line that this node appears on in the source code.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block of the loop.

parent: Optional[NodeNG]

The parent node in the syntax tree.

target: Optional[astroid.node_classes.NodeNG]

What the loop assigns to.

type_annotation: Optional[astroid.node_classes.NodeNG]

If present, this will contain the type annotation passed by a type comment

class astroid.nodes.AsyncFunctionDef(name=None, doc=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes.FunctionDef

Class representing an ast.FunctionDef node.

A AsyncFunctionDef is an asynchronous function created with the async keyword.

>>> node = astroid.extract_node('''
async def func(things):
    async for thing in things:
        print(thing)
''')
>>> node
<AsyncFunctionDef.func l.2 at 0x7f23b2e416d8>
>>> node.body[0]
<AsyncFor l.3 at 0x7f23b2e417b8>
Parameters
  • name (str or None) – The name of the function.

  • doc (str or None) – The function’s docstring.

  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.AsyncWith(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.With

Asynchronous with built with the async keyword.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

body: List[astroid.node_classes.NodeNG]

The contents of the with block.

col_offset: Optional[int]

The column that this node appears on in the source code.

items: List[Tuple[astroid.node_classes.NodeNG, Optional[astroid.node_classes.NodeNG]]]

The pairs of context managers and the names they are assigned to.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

type_annotation: Optional[astroid.node_classes.NodeNG]

If present, this will contain the type annotation passed by a type comment

class astroid.nodes.Attribute(attrname=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Attribute node.

Parameters
  • attrname (Optional[str]) – The name of the attribute.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(expr=None)[source]

Do some setup after initialisation.

Parameters

expr (Name or None) – The name that this node represents.

Return type

None

attrname: Optional[str]

The name of the attribute.

col_offset: Optional[int]

The column that this node appears on in the source code.

expr: Optional[astroid.node_classes.NodeNG]

The name that this node represents.

Type

Name or None

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.AugAssign(op=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.AugAssign node.

An AugAssign is an assignment paired with an operator.

>>> node = astroid.extract_node('variable += 1')
>>> node
<AugAssign l.1 at 0x7effe1db4d68>
Parameters
  • op (Optional[str]) – The operator that is being combined with the assignment. This includes the equals sign.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(target=None, value=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

type_errors(context=None)[source]

Get a list of type errors which can occur during inference.

Each TypeError is represented by a BadBinaryOperationMessage , which holds the original exception.

Returns

The list of possible type errors.

Return type

list(BadBinaryOperationMessage)

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

op: Optional[str]

The operator that is being combined with the assignment.

This includes the equals sign.

parent: Optional[NodeNG]

The parent node in the syntax tree.

target: Optional[astroid.node_classes.NodeNG]

What is being assigned to.

value: Optional[astroid.node_classes.NodeNG]

The value being assigned to the variable.

class astroid.nodes.Await(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Await node.

An Await is the await keyword.

>>> node = astroid.extract_node('''
async def func(things):
    await other_func()
''')
>>> node
<AsyncFunctionDef.func l.2 at 0x7f23b2e41748>
>>> node.body[0]
<Expr l.3 at 0x7f23b2e419e8>
>>> list(node.body[0].get_children())[0]
<Await l.3 at 0x7f23b2e41a20>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – What to wait for.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

What to wait for.

class astroid.nodes.BinOp(op=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.BinOp node.

A BinOp node is an application of a binary operator.

>>> node = astroid.extract_node('a + b')
>>> node
<BinOp l.1 at 0x7f23b2e8cfd0>
Parameters
  • op (Optional[str]) – The operator.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

op_left_associative()[source]
op_precedence()[source]
postinit(left=None, right=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

type_errors(context=None)[source]

Get a list of type errors which can occur during inference.

Each TypeError is represented by a BadBinaryOperationMessage, which holds the original exception.

Returns

The list of possible type errors.

Return type

list(BadBinaryOperationMessage)

col_offset: Optional[int]

The column that this node appears on in the source code.

left: Optional[astroid.node_classes.NodeNG]

What is being applied to the operator on the left side.

lineno: Optional[int]

The line that this node appears on in the source code.

op: Optional[str]

The operator.

parent: Optional[NodeNG]

The parent node in the syntax tree.

right: Optional[astroid.node_classes.NodeNG]

What is being applied to the operator on the right side.

class astroid.nodes.BoolOp(op=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.BoolOp node.

A BoolOp is an application of a boolean operator.

>>> node = astroid.extract_node('a and b')
>>> node
<BinOp l.1 at 0x7f23b2e71c50>
Parameters
  • op (Optional[str]) – The operator.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

op_precedence()[source]
postinit(values=None)[source]

Do some setup after initialisation.

Parameters

values (Optional[List[astroid.node_classes.NodeNG]]) – The values being applied to the operator.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

op: Optional[str]

The operator.

parent: Optional[NodeNG]

The parent node in the syntax tree.

values: List[astroid.node_classes.NodeNG]

The values being applied to the operator.

class astroid.nodes.Break(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Break node.

>>> node = astroid.extract_node('break')
>>> node
<Break l.1 at 0x7f23b2e9e5c0>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Call(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Call node.

A Call node is a call to a function, method, etc.

>>> node = astroid.extract_node('function()')
>>> node
<Call l.1 at 0x7f23b2e71eb8>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(func=None, args=None, keywords=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

args: List[astroid.node_classes.NodeNG]

The positional arguments being given to the call.

col_offset: Optional[int]

The column that this node appears on in the source code.

func: Optional[astroid.node_classes.NodeNG]

What is being called.

keywords: List[Keyword]

The keyword arguments being given to the call.

property kwargs: List[astroid.node_classes.Keyword]

The keyword arguments that unpack something.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

property starargs: List[astroid.node_classes.Starred]

The positional arguments that unpack something.

class astroid.nodes.ClassDef(name=None, doc=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.FilterStmtsMixin, astroid.scoped_nodes.LocalsDictNodeNG, astroid.node_classes.Statement

Class representing an ast.ClassDef node.

>>> node = astroid.extract_node('''
class Thing:
    def my_meth(self, arg):
        return arg + self.offset
''')
>>> node
<ClassDef.Thing l.2 at 0x7f23b2e9e748>
Parameters
  • name (str or None) – The name of the class.

  • doc (str or None) – The function’s docstring.

  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

ancestors(recurs=True, context=None)[source]

Iterate over the base classes in prefixed depth first order.

Parameters

recurs (bool) – Whether to recurse or return direct ancestors only.

Returns

The base classes

Return type

iterable(NodeNG)

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – Unused.

Returns

The range of line numbers that this node belongs to,

Return type

tuple(int, int)

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a ClassDef this is always True.

Return type

bool

callable()[source]

Whether this node defines something that is callable.

Returns

True if this defines something that is callable, False otherwise. For a ClassDef this is always True.

Return type

bool

declared_metaclass(context=None)[source]

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.

Return type

NodeNG or None

display_type()[source]

A human readable type of this node.

Returns

The type of this node.

Return type

str

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

getattr(name, context=None, class_context=True)[source]

Get an attribute from this class, using Python’s attribute semantic.

This method doesn’t look in the instance_attrs dictionary since it is done by an Instance proxy at inference time. It may return an 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.

Parameters
  • name (str) – The attribute to look for.

  • class_context (bool) – Whether the attribute can be accessed statically.

Returns

The attribute.

Return type

list(NodeNG)

Raises

AttributeInferenceError – If the attribute cannot be inferred.

getitem(index, context=None)[source]

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.

Return type

NodeNG

Raises

AstroidTypeError – If this class does not define a __getitem__ method.

has_base(node)[source]

Whether this class directly inherits from the given node.

Parameters

node (NodeNG) – The node to check for.

Returns

True if this class directly inherits from the given node.

Return type

bool

has_dynamic_getattr(context=None)[source]

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

True if the class has a custom __getattr__ or __getattribute__, False otherwise.

Return type

bool

has_metaclass_hack()[source]
igetattr(name, context=None, class_context=True)[source]

Infer the possible values of the given variable.

Parameters

name (str) – The name of the variable to infer.

Returns

The inferred possible values.

Return type

iterable(NodeNG or Uninferable)

implicit_locals()[source]

Get implicitly defined class definition locals.

Returns

the the name and Const pair for each local

Return type

tuple(tuple(str, node_classes.Const), …)

implicit_metaclass()[source]

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.

Return type

builtins.type or None

implicit_parameters()[source]
infer_binary_op(opnode, operator, other, context, method)
infer_call_result(caller, context=None)[source]

infer what a class is returning when called

instance_attr(name, context=None)[source]

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.

Return type

list(NodeNG)

Raises

AttributeInferenceError – If no attribute with this name can be found in this class or parent classes.

instance_attr_ancestors(name, context=None)[source]

Iterate over the parents that define the given name as an attribute.

Parameters

name (str) – The name to find definitions for.

Returns

The parents that define the given name as an instance attribute.

Return type

iterable(NodeNG)

instantiate_class()[source]

Get an Instance of the ClassDef node.

Returns

An Instance of the ClassDef node, or self if this is not possible.

Return type

Instance or ClassDef

is_subtype_of(type_name, context=None)[source]

Whether this class is a subtype of the given type.

Parameters

type_name (str) – The name of the type of check against.

Returns

True if this class is a subtype of the given type, False otherwise.

Return type

bool

local_attr(name, context=None)[source]

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.

Return type

list(NodeNG)

Raises

AttributeInferenceError – If no attribute with this name can be found in this class or parent classes.

local_attr_ancestors(name, context=None)[source]

Iterate over the parents that define the given name.

Parameters

name (str) – The name to find definitions for.

Returns

The parents that define the given name.

Return type

iterable(NodeNG)

metaclass(context=None)[source]

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.

Return type

NodeNG or None

methods()[source]

Iterate over all of the method defined in this class and its parents.

Returns

The methods defined on the class.

Return type

iterable(FunctionDef)

mro(context=None)[source]

Get the method resolution order, using C3 linearization.

Returns

The list of ancestors, sorted by the mro.

Return type

list(NodeNG)

Raises
mymethods()[source]

Iterate over all of the method defined in this class only.

Returns

The methods defined on the class.

Return type

iterable(FunctionDef)

postinit(bases, body, decorators, newstyle=None, metaclass=None, keywords=None)[source]

Do some setup after initialisation.

Parameters
  • bases (list(NodeNG)) – What the class inherits from.

  • body (list(NodeNG)) – The contents of the class body.

  • decorators (Decorators or None) – The decorators that are applied to this class.

  • newstyle (bool or None) – Whether this is a new style class or not.

  • metaclass (NodeNG or None) – The metaclass of this class.

  • keywords (list(Keyword) or None) – The keywords given to the class definition.

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

scope_lookup(node, name, offset=0)[source]

Lookup where the given name is assigned.

Parameters
  • node (NodeNG) – The node to look for assignments up to. Any assignments after the given node are ignored.

  • name (str) – The name to find assignments for.

  • offset (int) – The line offset to filter statements up to.

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

Return type

tuple(str, list(NodeNG))

slots()[source]

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.

Return type

list(str) or None

property basenames

The names of the parent classes

Names are given in the order they appear in the class definition.

Type

list(str)

bases

What the class inherits from.

Type

list(NodeNG)

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body

The contents of the class body.

Type

list(NodeNG)

col_offset: Optional[int]

The column that this node appears on in the source code.

decorators = None

The decorators that are applied to this class.

Type

Decorators or None

doc

The class’ docstring.

hide = False
keywords

The keywords given to the class definition.

This is usually for PEP 3115 style metaclass declaration.

Type

list(Keyword) or None

lineno: Optional[int]

The line that this node appears on in the source code.

name

The name of the class.

property newstyle

Whether this is a new style class or not

Type

bool or None

parent: Optional[NodeNG]

The parent node in the syntax tree.

special_attributes

The names of special attributes that this class has.

Type

objectmodel.ClassModel

property type

The class type for this node.

Possible values are: class, metaclass, exception.

Type

str

class astroid.nodes.Compare(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Compare node.

A Compare node indicates a comparison.

>>> node = astroid.extract_node('a <= b <= c')
>>> node
<Compare l.1 at 0x7f23b2e9e6d8>
>>> node.ops
[('<=', <Name.b l.1 at 0x7f23b2e9e2b0>), ('<=', <Name.c l.1 at 0x7f23b2e9e390>)]
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Overridden to handle the tuple fields and skip returning the operator strings.

Returns

The children.

Return type

iterable(NodeNG)

last_child()[source]

An optimized version of list(get_children())[-1]

Returns

The last child.

Return type

NodeNG

postinit(left=None, ops=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

left: Optional[astroid.node_classes.NodeNG]

The value at the left being applied to a comparison operator.

lineno: Optional[int]

The line that this node appears on in the source code.

ops: List[Tuple[str, astroid.node_classes.NodeNG]]

The remainder of the operators and their relevant right hand value.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Comprehension(parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.comprehension node.

A Comprehension indicates the loop inside any type of comprehension including generator expressions.

>>> node = astroid.extract_node('[x for x in some_values]')
>>> list(node.get_children())
[<Name.x l.1 at 0x7f23b2e352b0>, <Comprehension l.1 at 0x7f23b2e35320>]
>>> list(node.get_children())[1].as_string()
'for x in some_values'
Parameters

parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assign_type()[source]

The type of assignment that this node performs.

Returns

The assignment type.

Return type

NodeNG

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(target=None, iter=None, ifs=None, is_async=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

ifs: List[astroid.node_classes.NodeNG]

The contents of any if statements that filter the comprehension.

is_async: Optional[bool]

Whether this is an asynchronous comprehension or not.

iter: Optional[astroid.node_classes.NodeNG]

What is iterated over by the comprehension.

lineno: Optional[int]

The line that this node appears on in the source code.

optional_assign: ClassVar[bool] = True

Whether this node optionally assigns a variable.

parent: Optional[NodeNG]

The parent node in the syntax tree.

target: Optional[astroid.node_classes.NodeNG]

What is assigned to by the comprehension.

class astroid.nodes.Const(value, lineno=None, col_offset=None, parent=None, kind=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.NodeNG, astroid.bases.Instance

Class representing any constant including num, str, bool, None, bytes.

>>> node = astroid.extract_node('(5, "This is a string.", True, None, b"bytes")')
>>> node
<Tuple.tuple l.1 at 0x7f23b2e358d0>
>>> list(node.get_children())
[<Const.int l.1 at 0x7f23b2e35940>,
<Const.str l.1 at 0x7f23b2e35978>,
<Const.bool l.1 at 0x7f23b2e359b0>,
<Const.NoneType l.1 at 0x7f23b2e359e8>,
<Const.bytes l.1 at 0x7f23b2e35a20>]
Parameters
  • value (Any) – The value that the constant represents.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

  • kind (Optional[str]) – The string prefix. “u” for u-prefixed strings and None otherwise. Python 3.8+ only.

Return type

None

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node.

Return type

bool

getitem(index, context=None)[source]

Get an item from this node if subscriptable.

Parameters

index (Const or Slice) – The node to use as a subscript index.

Raises

AstroidTypeError – When the given index cannot be used as a subscript index, or if this node is not subscriptable.

has_dynamic_getattr()[source]

Check if the node has a custom __getattr__ or __getattribute__.

Returns

True if the class has a custom __getattr__ or __getattribute__, False otherwise. For a Const this is always False.

Return type

bool

infer_binary_op(opnode, operator, other, context, _)
infer_unary_op(op)
itered()[source]

An iterator over the elements this node contains.

Returns

The contents of this node.

Return type

iterable(Const)

Raises

TypeError – If this node does not represent something that is iterable.

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

kind: Optional[str]

“The string prefix. “u” for u-prefixed strings and None otherwise. Python 3.8+ only.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Any

The value that the constant represents.

class astroid.nodes.Continue(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Continue node.

>>> node = astroid.extract_node('continue')
>>> node
<Continue l.1 at 0x7f23b2e35588>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Decorators(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

A node representing a list of decorators.

A Decorators is the decorators that are applied to a method or function.

>>> node = astroid.extract_node('''
@property
def my_property(self):
    return 3
''')
>>> node
<FunctionDef.my_property l.2 at 0x7f23b2e35d30>
>>> list(node.get_children())[0]
<Decorators l.1 at 0x7f23b2e35d68>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(nodes)[source]

Do some setup after initialisation.

Parameters

nodes (list(Name or Call)) – The decorators that this node contains.

Return type

None

scope()[source]

The first parent node defining a new scope.

Returns

The first parent scope node.

Return type

Module or FunctionDef or ClassDef or Lambda or GenExpr

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

nodes: List[astroid.node_classes.NodeNG]

The decorators that this node contains.

Type

list(Name or Call) or None

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.DelAttr(attrname=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Variation of ast.Delete representing deletion of an attribute.

>>> node = astroid.extract_node('del self.attr')
>>> node
<Delete l.1 at 0x7f23b2e35f60>
>>> list(node.get_children())[0]
<DelAttr.attr l.1 at 0x7f23b2e411d0>
Parameters
  • attrname (Optional[str]) – The name of the attribute that is being deleted.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(expr=None)[source]

Do some setup after initialisation.

Parameters

expr (Name or None) – The name that this node represents.

Return type

None

attrname: Optional[str]

The name of the attribute that is being deleted.

col_offset: Optional[int]

The column that this node appears on in the source code.

expr: Optional[astroid.node_classes.NodeNG]

The name that this node represents.

Type

Name or None

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.DelName(name=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.LookupMixIn, astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Variation of ast.Delete representing deletion of a name.

A DelName is the name of something that is deleted.

>>> node = astroid.extract_node("del variable #@")
>>> list(node.get_children())
[<DelName.variable l.1 at 0x7effe1da4d30>]
>>> list(node.get_children())[0].as_string()
'variable'
Parameters
  • name (Optional[str]) – The name that is being deleted.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

name: Optional[str]

The name that is being deleted.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Delete(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.Delete node.

A Delete is a del statement this is deleting something.

>>> node = astroid.extract_node('del self.attr')
>>> node
<Delete l.1 at 0x7f23b2e35f60>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(targets=None)[source]

Do some setup after initialisation.

Parameters

targets (Optional[List[astroid.node_classes.NodeNG]]) – What is being deleted.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

targets: List[astroid.node_classes.NodeNG]

What is being deleted.

class astroid.nodes.Dict(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG, astroid.objects.DictInstance

Class representing an ast.Dict node.

A Dict is a dictionary that is created with {} syntax.

>>> node = astroid.extract_node('{1: "1"}')
>>> node
<Dict.dict l.1 at 0x7f23b2e35cc0>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node.

Return type

bool

classmethod from_elements(items=None)[source]

Create a Dict of constants from a live dictionary.

Parameters

items (dict) – The items to store in the node.

Returns

The created dictionary node.

Return type

Dict

get_children()[source]

Get the key and value nodes below this node.

Children are returned in the order that they are defined in the source code, key first then the value.

Returns

The children.

Return type

iterable(NodeNG)

getitem(index, context=None)[source]

Get an item from this node.

Parameters

index (Const or Slice) – The node to use as a subscript index.

Raises
  • AstroidTypeError – When the given index cannot be used as a subscript index, or if this node is not subscriptable.

  • AstroidIndexError – If the given index does not exist in the dictionary.

infer_unary_op(op)
itered()[source]

An iterator over the keys this node contains.

Returns

The keys of this node.

Return type

iterable(NodeNG)

last_child()[source]

An optimized version of list(get_children())[-1]

Returns

The last child, or None if no children exist.

Return type

NodeNG or None

postinit(items)[source]

Do some setup after initialisation.

Parameters

items (List[Tuple[astroid.node_classes.NodeNG, astroid.node_classes.NodeNG]]) – The key-value pairs contained in the dictionary.

Return type

None

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

items: List[Tuple[astroid.node_classes.NodeNG, astroid.node_classes.NodeNG]]

The key-value pairs contained in the dictionary.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.DictComp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes.ComprehensionScope

Class representing an ast.DictComp node.

>>> node = astroid.extract_node('{k:v for k, v in things if k > v}')
>>> node
<DictComp l.1 at 0x7f23b2e41d68>
Parameters
  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a DictComp this is always Uninferable.

Return type

Uninferable

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(key=None, value=None, generators=None)[source]

Do some setup after initialisation.

Parameters
  • key (NodeNG or None) – What produces the keys.

  • value (NodeNG or None) – What produces the values.

  • generators (list(Comprehension) or None) – The generators that are looped through.

col_offset: Optional[int]

The column that this node appears on in the source code.

generators = None

The generators that are looped through.

Type

list(Comprehension) or None

key = None

What produces the keys.

Type

NodeNG or None

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value = None

What produces the values.

Type

NodeNG or None

class astroid.nodes.DictUnpack(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.NodeNG

Represents the unpacking of dicts into dicts using PEP 448.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Ellipsis(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.NodeNG

Class representing an ast.Ellipsis node.

An Ellipsis is the ... syntax.

Deprecated since v2.6.0 - Use Const instead. Will be removed with the release v2.7.0

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.EmptyNode(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.NodeNG

Holds an arbitrary object in the LocalsDictNodeNG.locals.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

has_underlying_object()
col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

object = None
parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.ExceptHandler(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.ExceptHandler. node.

An ExceptHandler is an except block on a try-except.

>>> node = astroid.extract_node('''
    try:
        do_something()
    except Exception as error:
        print("Error!")
    ''')
>>> node
<TryExcept l.2 at 0x7f23b2e9d908>
>>> >>> node.handlers
[<ExceptHandler l.4 at 0x7f23b2e9e860>]
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
catch(exceptions)[source]

Check if this node handles any of the given

Parameters

exceptions (Optional[List[str]]) – The names of the exceptions to check for.

Return type

bool

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(type=None, name=None, body=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

:param body:The contents of the block.

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the block.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

name: Optional[astroid.node_classes.AssignName]

The name that the caught exception is assigned to.

parent: Optional[NodeNG]

The parent node in the syntax tree.

type: Optional[astroid.node_classes.NodeNG]

The types that the block handles.

Type

Tuple or NodeNG or None

class astroid.nodes.Expr(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing an ast.Expr node.

An Expr is any expression that does not have its value used or stored.

>>> node = astroid.extract_node('method()')
>>> node
<Call l.1 at 0x7f23b2e352b0>
>>> node.parent
<Expr l.1 at 0x7f23b2e35278>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – What the expression does.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

What the expression does.

class astroid.nodes.ExtSlice(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.ExtSlice node.

An ExtSlice is a complex slice expression.

Deprecated since v2.6.0 - Now part of the Subscript node. Will be removed with the release of v2.7.0

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.For(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.For node.

>>> node = astroid.extract_node('for thing in things: print(thing)')
>>> node
<For l.1 at 0x7f23b2e8cf28>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(target=None, iter=None, body=None, orelse=None, type_annotation=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the body of the loop.

col_offset: Optional[int]

The column that this node appears on in the source code.

iter: Optional[astroid.node_classes.NodeNG]

What the loop iterates over.

lineno: Optional[int]

The line that this node appears on in the source code.

optional_assign: ClassVar[bool] = True

Whether this node optionally assigns a variable.

This is always True for For nodes.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block of the loop.

parent: Optional[NodeNG]

The parent node in the syntax tree.

target: Optional[astroid.node_classes.NodeNG]

What the loop assigns to.

type_annotation: Optional[astroid.node_classes.NodeNG]

If present, this will contain the type annotation passed by a type comment

class astroid.nodes.FormattedValue(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.FormattedValue node.

Represents a PEP 498 format string.

>>> node = astroid.extract_node('f"Format {type_}"')
>>> node
<JoinedStr l.1 at 0x7f23b2e4ed30>
>>> node.values
[<Const.str l.1 at 0x7f23b2e4eda0>, <FormattedValue l.1 at 0x7f23b2e4edd8>]
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value, conversion=None, format_spec=None)[source]

Do some setup after initialisation.

Parameters
  • value (astroid.node_classes.NodeNG) – The value to be formatted into the string.

  • conversion (Optional[int]) – The type of formatting to be applied to the value.

  • format_spec (JoinedStr or None) – The formatting to be applied to the value.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

conversion: Optional[int]

The type of formatting to be applied to the value.

format_spec: Optional[astroid.node_classes.NodeNG]

The formatting to be applied to the value.

Type

JoinedStr or None

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: astroid.node_classes.NodeNG

The value to be formatted into the string.

class astroid.nodes.FunctionDef(name=None, doc=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.node_classes.Statement, astroid.scoped_nodes.Lambda

Class representing an ast.FunctionDef.

>>> node = astroid.extract_node('''
... def my_func(arg):
...     return arg + 1
... ''')
>>> node
<FunctionDef.my_func l.2 at 0x7f23b2e71e10>
Parameters
  • name (str or None) – The name of the function.

  • doc (str or None) – The function’s docstring.

  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – Unused.

Returns

The range of line numbers that this node belongs to,

Return type

tuple(int, int)

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a FunctionDef this is always True.

Return type

bool

decoratornames(context=None)[source]

Get the qualified names of each of the decorators on this function.

Parameters

context – An inference context that can be passed to inference functions

Returns

The names of the decorators.

Return type

set(str)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

getattr(name, context=None)[source]

this method doesn’t look in the instance_attrs dictionary since it’s done by an Instance proxy at inference time.

igetattr(name, context=None)[source]

Inferred getattr, which returns an iterator of inferred statements.

infer_call_result(caller=None, context=None)[source]

Infer what the function returns when called.

Returns

What the function returns.

Return type

iterable(NodeNG or Uninferable) or None

is_abstract(pass_is_abstract=True, any_raise_is_abstract=False)[source]

Check if the method is abstract.

A method is considered abstract if any of the following is true: * The only statement is ‘raise NotImplementedError’ * The only statement is ‘raise <SomeException>’ and any_raise_is_abstract is True * The only statement is ‘pass’ and pass_is_abstract is True * The method is annotated with abc.astractproperty/abc.abstractmethod

Returns

True if the method is abstract, False otherwise.

Return type

bool

is_bound()[source]

Check if the function is bound to an instance or class.

Returns

True if the function is bound to an instance or class, False otherwise.

Return type

bool

is_generator()[source]

Check if this is a generator function.

Returns

True is this is a generator function, False otherwise.

Return type

bool

is_method()[source]

Check if this function node represents a method.

Returns

True if this is a method, False otherwise.

Return type

bool

postinit(args, body, decorators=None, returns=None, type_comment_returns=None, type_comment_args=None)[source]

Do some setup after initialisation.

Parameters
  • args (Arguments or list) – The arguments that the function takes.

  • body (list(NodeNG)) – The contents of the function body.

  • decorators (Decorators or None) – The decorators that are applied to this method or function.

Params type_comment_returns

The return type annotation passed via a type comment.

Params type_comment_args

The args type annotation passed via a type comment.

scope_lookup(node, name, offset=0)[source]

Lookup where the given name is assigned.

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

col_offset: Optional[int]

The column that this node appears on in the source code.

decorators = None

The decorators that are applied to this method or function.

Type

Decorators or None

doc

The function’s docstring.

extra_decorators

<wrapped by the cachedproperty decorator> The extra decorators that this function can have.

Additional decorators are considered when they are used as assignments, as in method = staticmethod(method). The property will return all the callables that are used for decoration.

type

list(NodeNG)

fromlineno

<wrapped by the cachedproperty decorator> The first line that this node appears on in the source code.

type

int or None

is_function: ClassVar[bool] = True

Whether this node indicates a function.

For a FunctionDef this is always True.

Type

bool

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

returns = None
special_attributes

The names of special attributes that this function has.

Type

objectmodel.FunctionModel

type

<wrapped by the cachedproperty decorator> The function type for this node.

Possible values are: method, function, staticmethod, classmethod.

type

str

type_annotation = None

If present, this will contain the type annotation passed by a type comment

Type

NodeNG or None

type_comment_args = None

If present, this will contain the type annotation for arguments passed by a type comment

type_comment_returns = None

If present, this will contain the return type annotation, passed by a type comment

class astroid.nodes.GeneratorExp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes.ComprehensionScope

Class representing an ast.GeneratorExp node.

>>> node = astroid.extract_node('(thing for thing in things if thing)')
>>> node
<GeneratorExp l.1 at 0x7f23b2e4e400>
Parameters
  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a GeneratorExp this is always True.

Return type

bool

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(elt=None, generators=None)[source]

Do some setup after initialisation.

Parameters
  • elt (NodeNG or None) – The element that forms the output of the expression.

  • generators (list(Comprehension) or None) – The generators that are looped through.

col_offset: Optional[int]

The column that this node appears on in the source code.

elt = None

The element that forms the output of the expression.

Type

NodeNG or None

generators = None

The generators that are looped through.

Type

list(Comprehension) or None

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Global(names, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Global node.

>>> node = astroid.extract_node('global a_global')
>>> node
<Global l.1 at 0x7f23b2e9de10>
Parameters
  • names (List[str]) – The names being declared as global.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

names: List[str]

The names being declared as global.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.If(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.node_classes.Statement

Class representing an ast.If node.

>>> node = astroid.extract_node('if condition: print(True)')
>>> node
<If l.1 at 0x7f23b2e9dd30>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

has_elif_block()[source]
postinit(test=None, body=None, orelse=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the block.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block.

parent: Optional[NodeNG]

The parent node in the syntax tree.

test: Optional[astroid.node_classes.NodeNG]

The condition that the statement tests.

class astroid.nodes.IfExp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.IfExp node.

>>> node = astroid.extract_node('value if condition else other')
>>> node
<IfExp l.1 at 0x7f23b2e9dbe0>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

op_left_associative()[source]
postinit(test=None, body=None, orelse=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

body: Optional[astroid.node_classes.NodeNG]

The contents of the block.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

orelse: Optional[astroid.node_classes.NodeNG]

The contents of the else block.

parent: Optional[NodeNG]

The parent node in the syntax tree.

test: Optional[astroid.node_classes.NodeNG]

The condition that the statement tests.

class astroid.nodes.Import(names=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.mixins.ImportFromMixin, astroid.node_classes.Statement

Class representing an ast.Import node.

>>> node = astroid.extract_node('import astroid')
>>> node
<Import l.1 at 0x7f23b2e4e5c0>
Parameters
  • names (List[Tuple[str, Optional[str]]]) – The names being imported.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

names: List[Tuple[str, Optional[str]]]

The names being imported.

Each entry is a tuple of the name being imported, and the alias that the name is assigned to (if any).

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.ImportFrom(fromname, names, level=0, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.mixins.ImportFromMixin, astroid.node_classes.Statement

Class representing an ast.ImportFrom node.

>>> node = astroid.extract_node('from my_package import my_module')
>>> node
<ImportFrom l.1 at 0x7f23b2e415c0>
Parameters
  • fromname (Optional[str]) – The module that is being imported from.

  • names (List[Tuple[str, Optional[str]]]) – What is being imported from the module.

  • level (Optional[int]) – The level of relative import.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

level: Optional[int]

The level of relative import.

Essentially this is the number of dots in the import. This is always 0 for absolute imports.

lineno: Optional[int]

The line that this node appears on in the source code.

modname: Optional[str]

The module that is being imported from.

This is None for relative imports.

names: List[Tuple[str, Optional[str]]]

What is being imported from the module.

Each entry is a tuple of the name being imported, and the alias that the name is assigned to (if any).

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Index(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Index node.

An Index is a simple subscript.

Deprecated since v2.6.0 - Now part of the Subscript node. Will be removed with the release of v2.7.0

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.JoinedStr(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Represents a list of string expressions to be joined.

>>> node = astroid.extract_node('f"Format {type_}"')
>>> node
<JoinedStr l.1 at 0x7f23b2e4ed30>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(values=None)[source]

Do some setup after initialisation.

Parameters
Type

list(FormattedValue or Const)

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

values: List[astroid.node_classes.NodeNG]

The string expressions to be joined.

Type

list(FormattedValue or Const)

class astroid.nodes.Keyword(arg=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.keyword node.

>>> node = astroid.extract_node('function(a_kwarg=True)')
>>> node
<Call l.1 at 0x7f23b2e9e320>
>>> node.keywords
[<Keyword l.1 at 0x7f23b2e9e9b0>]
Parameters
  • arg (Optional[str]) – The argument being assigned to.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – The value being assigned to the ketword argument.

Return type

None

arg: Optional[str]

The argument being assigned to.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

The value being assigned to the keyword argument.

class astroid.nodes.Lambda(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.FilterStmtsMixin, astroid.scoped_nodes.LocalsDictNodeNG

Class representing an ast.Lambda node.

>>> node = astroid.extract_node('lambda arg: arg + 1')
>>> node
<Lambda.<lambda> l.1 at 0x7f23b2e41518>
Parameters
  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

argnames()[source]

Get the names of each of the arguments.

Returns

The names of the arguments.

Return type

list(str)

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a Lambda this is always True.

Return type

bool

callable()[source]

Whether this node defines something that is callable.

Returns

True if this defines something that is callable, False otherwise. For a Lambda this is always True.

Return type

bool

display_type()[source]

A human readable type of this node.

Returns

The type of this node.

Return type

str

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

implicit_parameters()[source]
infer_call_result(caller, context=None)[source]

Infer what the function returns when called.

Parameters

caller (object) – Unused

postinit(args, body)[source]

Do some setup after initialisation.

Parameters
  • args (Arguments) – The arguments that the function takes.

  • body (list(NodeNG)) – The contents of the function body.

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

scope_lookup(node, name, offset=0)[source]

Lookup where the given names is assigned.

Parameters
  • node (NodeNG) – The node to look for assignments up to. Any assignments after the given node are ignored.

  • name (str) – The name to find assignments for.

  • offset (int) – The line offset to filter statements up to.

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

Return type

tuple(str, list(NodeNG))

args

The arguments that the function takes.

Type

Arguments or list

body

The contents of the function body.

Type

list(NodeNG)

col_offset: Optional[int]

The column that this node appears on in the source code.

is_lambda: ClassVar[bool] = True
lineno: Optional[int]

The line that this node appears on in the source code.

name = '<lambda>'
parent: Optional[NodeNG]

The parent node in the syntax tree.

property type

Whether this is a method or function.

Returns

‘method’ if this is a method, ‘function’ otherwise.

Return type

str

class astroid.nodes.List(ctx=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes._BaseContainer

Class representing an ast.List node.

>>> node = astroid.extract_node('[1, 2, 3]')
>>> node
<List.list l.1 at 0x7f23b2e9e128>
Parameters
  • ctx (Optional[astroid.const.Context]) – Whether the list is assigned to or loaded from.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
getitem(index, context=None)[source]

Get an item from this node.

Parameters

index (Const or Slice) – The node to use as a subscript index.

infer_binary_op(opnode, operator, other, context, method)
infer_unary_op(op)
pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

ctx: Optional[astroid.const.Context]

Whether the list is assigned to or loaded from.

elts: List[astroid.node_classes.NodeNG]

The elements in the node.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.ListComp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes._ListComp, astroid.scoped_nodes.ComprehensionScope

Class representing an ast.ListComp node.

>>> node = astroid.extract_node('[thing for thing in things if thing]')
>>> node
<ListComp l.1 at 0x7f23b2e418d0>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Match(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing a ast.Match node.

>>> node = astroid.extract_node('''
match x:
    case 200:
        ...
    case _:
        ...
''')
>>> node
<Match l.2 at 0x10c24e170>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, subject, cases)[source]
Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchAs(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Pattern

Class representing a ast.MatchAs node.

>>> node = astroid.extract_node('''
match x:
    case [1, a]:
        ...
    case {'key': b}:
        ...
    case Point2D(0, 0) as c:
        ...
    case d:
        ...
''')
>>> node.cases[0].pattern.patterns[1]
<MatchAs l.3 at 0x10d0b2da0>
>>> node.cases[1].pattern.patterns[0]
<MatchAs l.5 at 0x10d0b2920>
>>> node.cases[2].pattern
<MatchAs l.7 at 0x10d0b06a0>
>>> node.cases[3].pattern
<MatchAs l.9 at 0x10d09b880>
Parameters
  • lineno (Optional[int]) –

  • col_offset (Optional[int]) –

  • parent (Optional[NodeNG]) –

Return type

None

postinit(*, pattern, name)[source]
Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchCase(*, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.node_classes.NodeNG

Class representing a ast.match_case node.

>>> node = astroid.extract_node('''
match x:
    case 200:
        ...
''')
>>> node.cases[0]
<MatchCase l.3 at 0x10c24e590>
Parameters

parent (Optional[NodeNG]) –

Return type

None

postinit(*, pattern, guard, body)[source]
Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchClass(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchClass node.

>>> node = astroid.extract_node('''
match x:
    case Point2D(0, 0):
        ...
    case Point3D(x=0, y=0, z=0):
        ...
''')
>>> node.cases[0].pattern
<MatchClass l.3 at 0x10ca83940>
>>> node.cases[1].pattern
<MatchClass l.5 at 0x10ca80880>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, cls, patterns, kwd_attrs, kwd_patterns)[source]
Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchMapping(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Pattern

Class representing a ast.MatchMapping node.

>>> node = astroid.extract_node('''
match x:
    case {1: "Hello", 2: "World", 3: _, **rest}:
        ...
''')
>>> node.cases[0].pattern
<MatchMapping l.3 at 0x10c8a8850>
Parameters
  • lineno (Optional[int]) –

  • col_offset (Optional[int]) –

  • parent (Optional[NodeNG]) –

Return type

None

postinit(*, keys, patterns, rest)[source]
Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchOr(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchOr node.

>>> node = astroid.extract_node('''
match x:
    case 400 | 401 | 402:
        ...
''')
>>> node.cases[0].pattern
<MatchOr l.3 at 0x10d0b0b50>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, patterns)[source]
Parameters

patterns (List[astroid.node_classes.Pattern]) –

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchSequence(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchSequence node.

>>> node = astroid.extract_node('''
match x:
    case [1, 2]:
        ...
    case (1, 2, *_):
        ...
''')
>>> node.cases[0].pattern
<MatchSequence l.3 at 0x10ca80d00>
>>> node.cases[1].pattern
<MatchSequence l.5 at 0x10ca80b20>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, patterns)[source]
Parameters

patterns (List[astroid.node_classes.Pattern]) –

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchSingleton(*, value, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchSingleton node.

>>> node = astroid.extract_node('''
match x:
    case True:
        ...
    case False:
        ...
    case None:
        ...
''')
>>> node.cases[0].pattern
<MatchSingleton l.3 at 0x10c2282e0>
>>> node.cases[1].pattern
<MatchSingleton l.5 at 0x10c228af0>
>>> node.cases[2].pattern
<MatchSingleton l.7 at 0x10c229f90>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

  • value (typing_extensions.Literal[True, False, None]) –

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchStar(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.Pattern

Class representing a ast.MatchStar node.

>>> node = astroid.extract_node('''
match x:
    case [1, *_]:
        ...
''')
>>> node.cases[0].pattern.patterns[1]
<MatchStar l.3 at 0x10ca809a0>
Parameters
  • lineno (Optional[int]) –

  • col_offset (Optional[int]) –

  • parent (Optional[NodeNG]) –

Return type

None

postinit(*, name)[source]
Parameters

name (Optional[astroid.node_classes.AssignName]) –

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.MatchValue(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Pattern

Class representing a ast.MatchValue node.

>>> node = astroid.extract_node('''
match x:
    case 200:
        ...
''')
>>> node.cases[0].pattern
<MatchValue l.3 at 0x10c24e200>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

postinit(*, value)[source]
Parameters

value (astroid.node_classes.NodeNG) –

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Module(name, doc, file=None, path=None, package=None, parent=None, pure_python=True)[source]

Bases: astroid.scoped_nodes.LocalsDictNodeNG

Class representing an ast.Module node.

>>> node = astroid.extract_node('import astroid')
>>> node
<Import l.1 at 0x7f23b2e4e5c0>
>>> node.parent
<Module l.0 at 0x7f23b2e4eda0>
Parameters
  • name (str) – The name of the module.

  • doc (str) – The module docstring.

  • file (str or None) – The path to the file that this ast has been extracted from.

  • path (Optional[List[str]]) –

  • package (bool or None) – Whether the node represents a package or a module.

  • parent (NodeNG or None) – The parent node in the syntax tree.

  • pure_python (bool or None) – Whether the ast was built from source.

absolute_import_activated()[source]

Whether PEP 328 absolute import behaviour has been enabled.

Returns

True if PEP 328 has been enabled, False otherwise.

Return type

bool

block_range(lineno)[source]

Get a range from where this node starts to where this node ends.

Parameters

lineno (int) – Unused.

Returns

The range of line numbers that this node belongs to.

Return type

tuple(int, int)

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a Module this is always True.

Return type

bool

display_type()[source]

A human readable type of this node.

Returns

The type of this node.

Return type

str

fully_defined()[source]

Check if this module has been build from a .py file.

If so, the module contains a complete representation, including the code.

Returns

True if the module has been built from a .py file.

Return type

bool

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

getattr(name, context=None, ignore_locals=False)[source]
igetattr(name, context=None)[source]

Infer the possible values of the given variable.

Parameters

name (str) – The name of the variable to infer.

Returns

The inferred possible values.

Return type

iterable(NodeNG) or None

import_module(modname, relative_only=False, level=None)[source]

Get the ast for a given module as if imported from this module.

Parameters
  • modname (str) – The name of the module to “import”.

  • relative_only (bool) – Whether to only consider relative imports.

  • level (int or None) – The level of relative import.

Returns

The imported module ast.

Return type

NodeNG

next_sibling()[source]

The next sibling statement node.

Returns

The next sibling statement node.

Return type

NodeNG or None

postinit(body=None)[source]

Do some setup after initialisation.

Parameters

body (list(NodeNG) or None) – The contents of the module.

previous_sibling()[source]

The previous sibling statement.

Returns

The previous sibling statement node.

Return type

NodeNG or None

public_names()[source]

The list of the names that are publicly available in this module.

Returns

The list of publc names.

Return type

list(str)

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

relative_to_absolute_name(modname, level)[source]

Get the absolute module name for a relative import.

The relative import can be implicit or explicit.

Parameters
  • modname (str) – The module name to convert.

  • level (int) – The level of relative import.

Returns

The absolute module name.

Return type

str

Raises

TooManyLevelsError – When the relative import refers to a module too far above this one.

scope_lookup(node, name, offset=0)[source]

Lookup where the given variable is assigned.

Parameters
  • node (NodeNG) – The node to look for assignments up to. Any assignments after the given node are ignored.

  • name (str) – The name of the variable to find assignments for.

  • offset (int) – The line offset to filter statements up to.

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

Return type

tuple(str, list(NodeNG))

statement()[source]

The first parent node, including self, marked as statement node.

Returns

The first parent statement.

Return type

NodeNG

stream()[source]

Get a stream to the underlying file or bytes.

Type

file or io.BytesIO or None

wildcard_import_names()[source]

The list of imported names when this module is ‘wildcard imported’.

It doesn’t include the ‘__builtins__’ name which is added by the current CPython implementation of wildcard imports.

Returns

The list of imported names.

Return type

list(str)

body

The contents of the module.

Type

list(NodeNG) or None

col_offset: Optional[int]

The column that this node appears on in the source code.

file = None

The path to the file that this ast has been extracted from.

This will be None when the representation has been built from a built-in module.

Type

str or None

file_bytes = None

The string/bytes that this ast was built from.

Type

str or bytes or None

file_encoding = None

The encoding of the source file.

This is used to get unicode out of a source file. Python 2 only.

Type

str or None

fromlineno = 0

The first line that this node appears on in the source code.

Type

int or None

future_imports = None

The imports from __future__.

Type

set(str) or None

globals = None

A map of the name of a global variable to the node defining the global.

Type

dict(str, NodeNG)

lineno: Optional[int] = 0

The line that this node appears on in the source code.

Type

int or None

name = None

The name of the module.

Type

str or None

package = None

Whether the node represents a package or a module.

Type

bool or None

parent: Optional[NodeNG]

The parent node in the syntax tree.

pure_python = None

Whether the ast was built from source.

Type

bool or None

scope_attrs = {'__doc__', '__file__', '__name__', '__package__', '__path__'}

The names of module attributes available through the global scope.

Type

str(str)

special_attributes

The names of special attributes that this module has.

Type

objectmodel.ModuleModel

class astroid.nodes.Name(name=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.LookupMixIn, astroid.node_classes.NodeNG

Class representing an ast.Name node.

A Name node is something that is named, but not covered by AssignName or DelName.

>>> node = astroid.extract_node('range(10)')
>>> node
<Call l.1 at 0x7effe1db8710>
>>> list(node.get_children())
[<Name.range l.1 at 0x7effe1db86a0>, <Const.int l.1 at 0x7effe1db8518>]
>>> list(node.get_children())[0].as_string()
'range'
Parameters
  • name (Optional[str]) – The name that this node refers to.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

name: Optional[str]

The name that this node refers to.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Nonlocal(names, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Nonlocal node.

>>> node = astroid.extract_node('''
def function():
    nonlocal var
''')
>>> node
<FunctionDef.function l.2 at 0x7f23b2e9e208>
>>> node.body[0]
<Nonlocal l.3 at 0x7f23b2e9e908>
Parameters
  • names (List[str]) – The names being declared as not local.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

names: List[str]

The names being declared as not local.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Pass(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.NoChildrenMixin, astroid.node_classes.Statement

Class representing an ast.Pass node.

>>> node = astroid.extract_node('pass')
>>> node
<Pass l.1 at 0x7f23b2e9e748>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Raise(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing an ast.Raise node.

>>> node = astroid.extract_node('raise RuntimeError("Something bad happened!")')
>>> node
<Raise l.1 at 0x7f23b2e9e828>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(exc=None, cause=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

raises_not_implemented()[source]

Check if this node raises a NotImplementedError.

Returns

True if this node raises a NotImplementedError, False otherwise.

Return type

bool

cause: Optional[astroid.node_classes.NodeNG]

The exception being used to raise this one.

col_offset: Optional[int]

The column that this node appears on in the source code.

exc: Optional[astroid.node_classes.NodeNG]

What is being raised.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Return(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Statement

Class representing an ast.Return node.

>>> node = astroid.extract_node('return True')
>>> node
<Return l.1 at 0x7f23b8211908>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

is_tuple_return()[source]
postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – The value being returned.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

The value being returned.

class astroid.nodes.Set(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes._BaseContainer

Class representing an ast.Set node.

>>> node = astroid.extract_node('{1, 2, 3}')
>>> node
<Set.set l.1 at 0x7f23b2e71d68>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

infer_unary_op(op)
pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

elts: List[astroid.node_classes.NodeNG]

The elements in the node.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.SetComp(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.scoped_nodes.ComprehensionScope

Class representing an ast.SetComp node.

>>> node = astroid.extract_node('{thing for thing in things if thing}')
>>> node
<SetComp l.1 at 0x7f23b2e41898>
Parameters
  • lineno (int or None) – The line that this node appears on in the source code.

  • col_offset (int or None) – The column that this node appears on in the source code.

  • parent (NodeNG or None) – The parent node in the syntax tree.

bool_value(context=None)[source]

Determine the boolean value of this node.

Returns

The boolean value of this node. For a SetComp this is always Uninferable.

Return type

Uninferable

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(elt=None, generators=None)[source]

Do some setup after initialisation.

Parameters
  • elt (NodeNG or None) – The element that forms the output of the expression.

  • generators (list(Comprehension) or None) – The generators that are looped through.

col_offset: Optional[int]

The column that this node appears on in the source code.

elt = None

The element that forms the output of the expression.

Type

NodeNG or None

generators = None

The generators that are looped through.

Type

list(Comprehension) or None

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Slice(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Slice node.

>>> node = astroid.extract_node('things[1:3]')
>>> node
<Subscript l.1 at 0x7f23b2e71f60>
>>> node.slice
<Slice l.1 at 0x7f23b2e71e80>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

getattr(attrname, context=None)[source]
igetattr(attrname, context=None)[source]

Infer the possible values of the given attribute on the slice.

Parameters

attrname (str) – The name of the attribute to infer.

Returns

The inferred possible values.

Return type

iterable(NodeNG)

postinit(lower=None, upper=None, step=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

lower: Optional[astroid.node_classes.NodeNG]

The lower index in the slice.

parent: Optional[NodeNG]

The parent node in the syntax tree.

step: Optional[astroid.node_classes.NodeNG]

The step to take between indexes.

upper: Optional[astroid.node_classes.NodeNG]

The upper index in the slice.

class astroid.nodes.Starred(ctx=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.ParentAssignTypeMixin, astroid.node_classes.NodeNG

Class representing an ast.Starred node.

>>> node = astroid.extract_node('*args')
>>> node
<Starred l.1 at 0x7f23b2e41978>
Parameters
  • ctx (Optional[astroid.const.Context]) – Whether the list is assigned to or loaded from.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
Parameters
  • self – nodes.Starred

  • node – a node related to the current underlying Node.

  • context – Inference context used for caching already inferred objects

  • assign_path – A list of indices, where each index specifies what item to fetch from the inference results.

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – What is being unpacked.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

ctx: Optional[astroid.const.Context]

Whether the starred item is assigned to or loaded from.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

What is being unpacked.

class astroid.nodes.Subscript(ctx=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Subscript node.

>>> node = astroid.extract_node('things[1:3]')
>>> node
<Subscript l.1 at 0x7f23b2e71f60>
Parameters
  • ctx (Optional[astroid.const.Context]) – Whether the subscripted item is assigned to or loaded from.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

infer_lhs(context=None)

Inference for subscripts

We’re understanding if the index is a Const or a slice, passing the result of inference to the value’s getitem method, which should handle each supported index type accordingly.

postinit(value=None, slice=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

ctx: Optional[astroid.const.Context]

Whether the subscripted item is assigned to or loaded from.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

slice: Optional[astroid.node_classes.NodeNG]

The slice being used to lookup.

value: Optional[astroid.node_classes.NodeNG]

What is being indexed.

class astroid.nodes.TryExcept(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.node_classes.Statement

Class representing an ast.TryExcept node.

>>> node = astroid.extract_node('''
    try:
        do_something()
    except Exception as error:
        print("Error!")
    ''')
>>> node
<TryExcept l.2 at 0x7f23b2e9d908>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(body=None, handlers=None, orelse=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

body: List[astroid.node_classes.NodeNG]

The contents of the block to catch exceptions from.

col_offset: Optional[int]

The column that this node appears on in the source code.

handlers: List[astroid.node_classes.ExceptHandler]

The exception handlers.

lineno: Optional[int]

The line that this node appears on in the source code.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.TryFinally(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.node_classes.Statement

Class representing an ast.TryFinally node.

>>> node = astroid.extract_node('''
try:
    do_something()
except Exception as error:
    print("Error!")
finally:
    print("Cleanup!")
''')
>>> node
<TryFinally l.2 at 0x7f23b2e41d68>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(body=None, finalbody=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

body: Union[List[astroid.node_classes.TryExcept], List[astroid.node_classes.NodeNG]]

The try-except that the finally is attached to.

col_offset: Optional[int]

The column that this node appears on in the source code.

finalbody: List[astroid.node_classes.NodeNG]

The contents of the finally block.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Tuple(ctx=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes._BaseContainer

Class representing an ast.Tuple node.

>>> node = astroid.extract_node('(1, 2, 3)')
>>> node
<Tuple.tuple l.1 at 0x7f23b2e41780>
Parameters
  • ctx (Optional[astroid.const.Context]) – Whether the tuple is assigned to or loaded from.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)
getitem(index, context=None)[source]

Get an item from this node.

Parameters

index (Const or Slice) – The node to use as a subscript index.

infer_binary_op(opnode, operator, other, context, method)
infer_unary_op(op)
pytype()[source]

Get the name of the type that this node represents.

Returns

The name of the type.

Return type

str

col_offset: Optional[int]

The column that this node appears on in the source code.

ctx: Optional[astroid.const.Context]

Whether the tuple is assigned to or loaded from.

elts: List[astroid.node_classes.NodeNG]

The elements in the node.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.UnaryOp(op=None, lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.UnaryOp node.

>>> node = astroid.extract_node('-5')
>>> node
<UnaryOp l.1 at 0x7f23b2e4e198>
Parameters
  • op (Optional[str]) – The operator.

  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

op_precedence()[source]
postinit(operand=None)[source]

Do some setup after initialisation.

Parameters

operand (Optional[astroid.node_classes.NodeNG]) – What the unary operator is applied to.

Return type

None

type_errors(context=None)[source]

Get a list of type errors which can occur during inference.

Each TypeError is represented by a BadBinaryOperationMessage, which holds the original exception.

Returns

The list of possible type errors.

Return type

list(BadBinaryOperationMessage)

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

op: Optional[str]

The operator.

operand: Optional[astroid.node_classes.NodeNG]

What the unary operator is applied to.

parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.Unknown(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.AssignTypeMixin, astroid.node_classes.NodeNG

This node represents a node in a constructed AST where introspection is not possible. At the moment, it’s only used in the args attribute of FunctionDef nodes where function signature introspection failed.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

infer(context=None, **kwargs)[source]

Inference on an Unknown node immediately terminates.

qname()[source]
col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

name = 'Unknown'
parent: Optional[NodeNG]

The parent node in the syntax tree.

class astroid.nodes.While(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.node_classes.Statement

Class representing an ast.While node.

>>> node = astroid.extract_node('''
while condition():
    print("True")
''')
>>> node
<While l.2 at 0x7f23b2e4e390>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

block_range(lineno)[source]

Get a range from the given line number to where this node ends.

Parameters

lineno (int) – The line number to start the range at.

Returns

The range of line numbers that this node belongs to, starting at the given line number.

Return type

tuple(int, int)

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(test=None, body=None, orelse=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the loop.

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

orelse: List[astroid.node_classes.NodeNG]

The contents of the else block.

parent: Optional[NodeNG]

The parent node in the syntax tree.

test: Optional[astroid.node_classes.NodeNG]

The condition that the loop tests.

class astroid.nodes.With(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.mixins.MultiLineBlockMixin, astroid.mixins.BlockRangeMixIn, astroid.mixins.AssignTypeMixin, astroid.node_classes.Statement

Class representing an ast.With node.

>>> node = astroid.extract_node('''
with open(file_path) as file_:
    print(file_.read())
''')
>>> node
<With l.2 at 0x7f23b2e4e710>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

assigned_stmts(node=None, context=None, assign_path=None)

Infer names and other nodes from a with statement.

This enables only inference for name binding in a with statement. For instance, in the following code, inferring func will return the ContextManager class, not whatever __enter__ returns. We are doing this intentionally, because we consider that the context manager result is whatever __enter__ returns and what it is binded using the as keyword.

class ContextManager(object):
def __enter__(self):

return 42

with ContextManager() as f:

pass

# ContextManager().infer() will return ContextManager # f.infer() will return 42.

Parameters
  • self – nodes.With

  • node – The target of the assignment, as (a, b) in with foo as (a, b).

  • context – Inference context used for caching already inferred objects

  • assign_path – A list of indices, where each index specifies what item to fetch from the inference results.

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(items=None, body=None, type_annotation=None)[source]

Do some setup after initialisation.

Parameters
Return type

None

blockstart_tolineno

<wrapped by the cachedproperty decorator> The line on which the beginning of this block ends.

type

int

body: List[astroid.node_classes.NodeNG]

The contents of the with block.

col_offset: Optional[int]

The column that this node appears on in the source code.

items: List[Tuple[astroid.node_classes.NodeNG, Optional[astroid.node_classes.NodeNG]]]

The pairs of context managers and the names they are assigned to.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

type_annotation: Optional[astroid.node_classes.NodeNG]

If present, this will contain the type annotation passed by a type comment

class astroid.nodes.Yield(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.NodeNG

Class representing an ast.Yield node.

>>> node = astroid.extract_node('yield True')
>>> node
<Yield l.1 at 0x7f23b2e4e5f8>
Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

get_children()[source]

Get the child nodes below this node.

Returns

The children.

Return type

iterable(NodeNG)

postinit(value=None)[source]

Do some setup after initialisation.

Parameters

value (Optional[astroid.node_classes.NodeNG]) – The value to yield.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

The value to yield.

class astroid.nodes.YieldFrom(lineno=None, col_offset=None, parent=None)[source]

Bases: astroid.node_classes.Yield

Class representing an ast.YieldFrom node.

Parameters
  • lineno (Optional[int]) – The line that this node appears on in the source code.

  • col_offset (Optional[int]) – The column that this node appears on in the source code.

  • parent (Optional[NodeNG]) – The parent node in the syntax tree.

Return type

None

col_offset: Optional[int]

The column that this node appears on in the source code.

lineno: Optional[int]

The line that this node appears on in the source code.

parent: Optional[NodeNG]

The parent node in the syntax tree.

value: Optional[astroid.node_classes.NodeNG]

The value to yield.