Exceptions

This module contains exceptions used in the astroid library.

Exceptions

AstroidBuildingError([message, modname, ...])

Exception class when we are unable to build an astroid representation.

AstroidError([message])

Base exception class for all astroid related exceptions.

AstroidImportError([message, modname, ...])

Exception class used when a module can't be imported by astroid.

AstroidIndexError([message, node, index, ...])

Raised when an Indexable / Mapping does not have an index / key.

AstroidSyntaxError(message, modname, error, path)

Exception class used when a module can't be parsed.

AstroidTypeError([message, node, index, context])

Raised when a TypeError would be expected in Python code.

AttributeInferenceError([message, ...])

Raised when an attribute lookup fails, corresponds to AttributeError.

DuplicateBasesError(message, mros, cls[, ...])

Error raised when there are duplicate bases in the same class bases.

InconsistentMroError(message, mros, cls[, ...])

Error raised when a class's MRO is inconsistent.

InferenceError([message, node, context, ...])

Raised when we are unable to infer a node.

MroError(message, mros, cls[, context])

Error raised when there is a problem with method resolution of a class.

NameInferenceError([message, name, scope, ...])

Raised when a name lookup fails, corresponds to NameError.

NoDefault([message, func, name])

Raised by function's default_value method when an argument has no default value.

NotFoundError

alias of AttributeInferenceError

ParentMissingError(target)

Raised when a node which is expected to have a parent attribute is missing one.

ResolveError([message, context])

Base class of astroid resolution/inference error.

SuperArgumentTypeError

alias of SuperError

SuperError(message, super_, **kws)

Error raised when there is a problem with a super call.

TooManyLevelsError([message, level, name])

Exception class which is raised when a relative import was beyond the top-level.

UnresolvableName

alias of NameInferenceError

UseInferenceDefault

Exception to be raised in custom inference function to indicate that it should go back to the default behaviour.

exception astroid.exceptions.AstroidBuildingError(message: str = 'Failed to import module {modname}.', modname: str | None = None, error: Exception | None = None, source: str | None = None, path: str | None = None, cls: type | None = None, class_repr: str | None = None, **kws: Any)[source]

Bases: AstroidError

Exception class when we are unable to build an astroid representation.

Standard attributes:

modname: Name of the module that AST construction failed for. error: Exception raised during construction.

exception astroid.exceptions.AstroidError(message: str = '', **kws: Any)[source]

Bases: Exception

Base exception class for all astroid related exceptions.

AstroidError and its subclasses are structured, intended to hold objects representing state when the exception is thrown. Field values are passed to the constructor as keyword-only arguments. Each subclass has its own set of standard fields, but use your best judgment to decide whether a specific exception instance needs more or fewer fields for debugging. Field values may be used to lazily generate the error message: self.message.format() will be called with the field names and values supplied as keyword arguments.

exception astroid.exceptions.AstroidImportError(message: str = 'Failed to import module {modname}.', modname: str | None = None, error: Exception | None = None, source: str | None = None, path: str | None = None, cls: type | None = None, class_repr: str | None = None, **kws: Any)[source]

Bases: AstroidBuildingError

Exception class used when a module can’t be imported by astroid.

exception astroid.exceptions.AstroidIndexError(message: str = '', node: nodes.NodeNG | bases.Instance | None = None, index: nodes.Subscript | None = None, context: InferenceContext | None = None, **kws: Any)[source]

Bases: AstroidError

Raised when an Indexable / Mapping does not have an index / key.

exception astroid.exceptions.AstroidSyntaxError(message: str, modname: str | None, error: Exception, path: str | None, source: str | None = None)[source]

Bases: AstroidBuildingError

Exception class used when a module can’t be parsed.

exception astroid.exceptions.AstroidTypeError(message: str = '', node: nodes.NodeNG | bases.Instance | None = None, index: nodes.Subscript | None = None, context: InferenceContext | None = None, **kws: Any)[source]

Bases: AstroidError

Raised when a TypeError would be expected in Python code.

exception astroid.exceptions.AstroidValueError(message: str = '', **kws: Any)[source]

Bases: AstroidError

Raised when a ValueError would be expected in Python code.

exception astroid.exceptions.AttributeInferenceError(message: str = '{attribute!r} not found on {target!r}.', attribute: str = '', target: nodes.NodeNG | bases.BaseInstance | None = None, context: InferenceContext | None = None, mros: list[nodes.ClassDef] | None = None, super_: nodes.ClassDef | None = None, cls: nodes.ClassDef | None = None, **kws: Any)[source]

Bases: ResolveError

Raised when an attribute lookup fails, corresponds to AttributeError.

Standard attributes:

target: The node for which lookup failed. attribute: The attribute for which lookup failed, as a string. context: InferenceContext object.

exception astroid.exceptions.DuplicateBasesError(message: str, mros: Iterable[Iterable[nodes.ClassDef]], cls: nodes.ClassDef, context: InferenceContext | None = None, **kws: Any)[source]

Bases: MroError

Error raised when there are duplicate bases in the same class bases.

exception astroid.exceptions.InconsistentMroError(message: str, mros: Iterable[Iterable[nodes.ClassDef]], cls: nodes.ClassDef, context: InferenceContext | None = None, **kws: Any)[source]

Bases: MroError

Error raised when a class’s MRO is inconsistent.

exception astroid.exceptions.InferenceError(message: str = 'Inference failed for {node!r}.', node: InferenceResult | None = None, context: InferenceContext | None = None, target: InferenceResult | None = None, targets: InferenceResult | None = None, attribute: str | None = None, unknown: InferenceResult | None = None, assign_path: list[int] | None = None, caller: SuccessfulInferenceResult | None = None, stmts: Iterator[InferenceResult] | None = None, frame: InferenceResult | None = None, call_site: arguments.CallSite | None = None, func: InferenceResult | None = None, arg: str | None = None, positional_arguments: list | None = None, unpacked_args: list | None = None, keyword_arguments: dict | None = None, unpacked_kwargs: dict | None = None, **kws: Any)[source]

Bases: ResolveError

Raised when we are unable to infer a node.

Standard attributes:

node: The node inference was called on. context: InferenceContext object.

exception astroid.exceptions.InferenceOverwriteError(message: str = '', **kws: Any)[source]

Bases: AstroidError

Raised when an inference tip is overwritten.

Currently only used for debugging.

exception astroid.exceptions.MroError(message: str, mros: Iterable[Iterable[nodes.ClassDef]], cls: nodes.ClassDef, context: InferenceContext | None = None, **kws: Any)[source]

Bases: ResolveError

Error raised when there is a problem with method resolution of a class.

Standard attributes:

mros: A sequence of sequences containing ClassDef nodes. cls: ClassDef node whose MRO resolution failed. context: InferenceContext object.

exception astroid.exceptions.NameInferenceError(message: str = '{name!r} not found in {scope!r}.', name: str | None = None, scope: nodes.LocalsDictNodeNG | None = None, context: InferenceContext | None = None, **kws: Any)[source]

Bases: InferenceError

Raised when a name lookup fails, corresponds to NameError.

Standard attributes:

name: The name for which lookup failed, as a string. scope: The node representing the scope in which the lookup occurred. context: InferenceContext object.

exception astroid.exceptions.NoDefault(message: str = '{func!r} has no default for {name!r}.', func: nodes.FunctionDef | None = None, name: str | None = None, **kws: Any)[source]

Bases: AstroidError

Raised by function’s default_value method when an argument has no default value.

Standard attributes:

func: Function node. name: Name of argument without a default.

astroid.exceptions.NotFoundError

alias of AttributeInferenceError

exception astroid.exceptions.ParentMissingError(target: nodes.NodeNG)[source]

Bases: AstroidError

Raised when a node which is expected to have a parent attribute is missing one.

Standard attributes:

target: The node for which the parent lookup failed.

exception astroid.exceptions.ResolveError(message: str = '', context: InferenceContext | None = None, **kws: Any)[source]

Bases: AstroidError

Base class of astroid resolution/inference error.

ResolveError is not intended to be raised.

Standard attributes:

context: InferenceContext object.

exception astroid.exceptions.StatementMissing(target: nodes.NodeNG)[source]

Bases: ParentMissingError

Raised when a call to node.statement() does not return a node.

This is because a node in the chain does not have a parent attribute and therefore does not return a node for statement().

Standard attributes:

target: The node for which the parent lookup failed.

astroid.exceptions.SuperArgumentTypeError

alias of SuperError

exception astroid.exceptions.SuperError(message: str, super_: objects.Super, **kws: Any)[source]

Bases: ResolveError

Error raised when there is a problem with a super call.

Standard attributes:

super_: The Super instance that raised the exception. context: InferenceContext object.

exception astroid.exceptions.TooManyLevelsError(message: str = 'Relative import with too many levels ({level}) for module {name!r}', level: int | None = None, name: str | None = None, **kws: Any)[source]

Bases: AstroidImportError

Exception class which is raised when a relative import was beyond the top-level.

Standard attributes:

level: The level which was attempted. name: the name of the module on which the relative import was attempted.

astroid.exceptions.UnresolvableName

alias of NameInferenceError

exception astroid.exceptions.UseInferenceDefault[source]

Bases: Exception

Exception to be raised in custom inference function to indicate that it should go back to the default behaviour.