### Example of upgrading to development version Source: https://github.com/pylint-dev/astroid/blob/main/doc/release.md An example demonstrating the process of bumping to a development version after a stable release, including the subsequent manual commit message. ```bash tbump 2.5.0-dev0 --no-tag --no-push git commit -am "Upgrade the version to 2.5.0-dev0 following 2.4.0 release" ``` -------------------------------- ### Install Astroid Source: https://github.com/pylint-dev/astroid/blob/main/README.rst Install astroid using pip. For an editable installation, use the -e flag. ```bash pip install . ``` ```bash pip install -e . ``` -------------------------------- ### Example of bumping patch version Source: https://github.com/pylint-dev/astroid/blob/main/doc/release.md An example of using `tbump` to set a specific patch version, such as 2.3.5, without immediately pushing or tagging the release. ```bash tbump 2.3.5 --no-tag --no-push ``` -------------------------------- ### Parsing Python code to AST Source: https://github.com/pylint-dev/astroid/blob/main/doc/inference.md Use astroid.parse() to get an Abstract Syntax Tree (AST) from a Python code string. The repr_tree() method is useful for inspecting the structure of the parsed tree. ```python >>> tree = astroid.parse('a + b') >>> tree >>> >>> print(tree.repr_tree()) Module( name='', doc=None, file='', path=[''], package=False, pure_python=True, future_imports=set(), body=[Expr(value=BinOp( op='+', left=Name(name='a'), right=Name(name='b')))]) ``` -------------------------------- ### Instantiating a new FunctionDef node Source: https://github.com/pylint-dev/astroid/blob/main/doc/extending.md Demonstrates how to instantiate a new FunctionDef node, including setting its name, line number, column offset, and parent. It also shows the use of postinit for arguments like args, body, returns, and doc_node. ```python new_node = FunctionDef( name='my_new_function', lineno=3, col_offset=0, parent=the_parent_of_this_function, ) new_node.postinit( args=args, body=body, returns=returns, doc_node=nodes.Const(value='the docstring of this function'), ) ``` -------------------------------- ### Run Tests with Tox Source: https://github.com/pylint-dev/astroid/blob/main/README.rst Launch the entire test suite using tox. ```bash tox ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/pylint-dev/astroid/blob/main/README.rst Launch the entire test suite using pytest. ```bash pytest ``` -------------------------------- ### Parsing and Inferring Python Code with Astroid Source: https://github.com/pylint-dev/astroid/blob/main/doc/index.md Demonstrates how to parse Python code into an AST and infer values of variables and function calls using astroid. This is useful for static analysis and understanding code behavior. ```python from astroid import parse module = parse(''' def func(first, second): return first + second arg_1 = 2 arg_2 = 3 func(arg_1, arg_2) ''') >>> module.body[-1] >>> inferred = next(module.body[-1].value.infer()) >>> inferred >>> inferred.value 5 ``` -------------------------------- ### Instance.getitem Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Infers the result of item access on an instance using an index. ```APIDOC ## Instance.getitem(index: nodes.Const, context: InferenceContext | None = None) -> InferenceResult | None ### Description Infers the result of item access on an instance using a provided index. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example - None ### Response #### Success Response (200) - Returns an `InferenceResult` object or `None` if the item cannot be inferred. ``` -------------------------------- ### Upgrade to development version after release Source: https://github.com/pylint-dev/astroid/blob/main/doc/release.md After releasing a stable version, use `tbump` to set the next development version. This command is often interrupted after the initial version bump, followed by a manual commit. ```bash tbump X.Y+1.0-dev0 --no-tag --no-push git commit -am "Upgrade the version to x.y+1.0-dev0 following x.y.0 release" ``` -------------------------------- ### Verifying AST transform with as_string() Source: https://github.com/pylint-dev/astroid/blob/main/doc/extending.md This snippet demonstrates how to parse a string containing a '.format()' call and then print its string representation after an AST transform has been applied. It's used to verify the correctness of the transform. ```python from astroid import parse tree = parse(''' "my name is {}".format(name) ''') print(tree.as_string()) ``` -------------------------------- ### Tag and push release Source: https://github.com/pylint-dev/astroid/blob/main/doc/release.md After a successful code review and merge of a patch release, create and push the Git tag corresponding to the released version. ```bash git tag vX.Y-1.Z && git push --tags ``` -------------------------------- ### Registering a basic transform Source: https://github.com/pylint-dev/astroid/blob/main/doc/extending.md This snippet shows the initial registration of a transform function for astroid.Call nodes. The transform function currently returns the node unmodified. ```python def format_to_fstring_transform(node): return node astroid.MANAGER.register_transform(...) ``` -------------------------------- ### Registering a Module Extender Transform Source: https://github.com/pylint-dev/astroid/blob/main/doc/extending.md Use `register_module_extender` to add new nodes to an existing module. The transform function should return an `astroid.Module` instance. ```python def my_custom_module(): return astroid.parse(''' class SomeClass: ... class SomeOtherClass: ... ''') register_module_extender(astroid.MANAGER, 'mymodule', my_custom_module) ``` -------------------------------- ### astroid.inference_tip Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Provides a transform function for registering custom inference functions with AstroidManager. ```APIDOC ## astroid.inference_tip(infer_function: InferFn[_NodesT], raise_on_overwrite: bool = False) -> TransformFn[_NodesT] ### Description Given an instance-specific inference function, returns a function suitable for `AstroidManager().register_transform`. This allows setting custom inference logic. ### Parameters * **infer_function** (InferFn[_NodesT]): The custom inference function to be used. * **raise_on_overwrite** (bool, optional): If True, raises an `InferenceOverwriteError` if the inference tip overwrites an existing one. Defaults to False. #### NOTE Using an inference tip will override any previously set inference tip for the given node. Use a predicate in the transform to prevent excess overwrites. ``` -------------------------------- ### Bump version and release patch (no push/tag) Source: https://github.com/pylint-dev/astroid/blob/main/doc/release.md Use `tbump` to increment the version for a patch release without pushing or tagging. This is done before code review and allows for visual inspection of the changes. ```bash tbump X.Y-1.Z --no-tag --no-push ``` -------------------------------- ### astroid.parse Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Parses Python code into an astroid AST. ```APIDOC ## astroid.parse(code: str, module_name: str = '', path: str | None = None, apply_transforms: bool = True) -> Module ### Description Parses a source string into an astroid AST (Abstract Syntax Tree). ### Parameters * **code** (str): The Python code for the module. * **module_name** (str, optional): The name for the module. Defaults to ''. * **path** (str | None, optional): The path for the module. Defaults to None. * **apply_transforms** (bool, optional): Whether to apply the default transforms for the given code. Use `False` if you don’t want the default transforms to be applied. Defaults to True. ### Returns A `Module` node representing the root of the AST. ``` -------------------------------- ### Registering an inference tip for AstroidManager Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Use inference_tip to provide a custom inference function to AstroidManager. This overrides existing inference tips for the given node. ```python AstroidManager().register_transform(Call, inference_tip(infer_named_tuple), predicate) ``` -------------------------------- ### Bump version and release major/minor (no push/tag) Source: https://github.com/pylint-dev/astroid/blob/main/doc/release.md Use `tbump` to increment the version for a major or minor release without pushing or tagging immediately. This is typically followed by manual commit amendments and branch updates. ```bash tbump X.Y.0 --no-push --no-tag ``` -------------------------------- ### Registering an AST Inference Tip Transform Source: https://github.com/pylint-dev/astroid/blob/main/doc/extending.md Use `inference_tip` to wrap a transform function that provides inference for specific AST nodes, like function calls. The transform should return an iterator of new nodes. ```python def infer_my_custom_call(call_node, context=None): # Do some transformation here return iter((new_node, )) MANAGER.register_transform( nodes.Call, inference_tip(infer_my_custom_call), _looks_like_my_custom_call, ) ``` -------------------------------- ### Parsing Python code into an AST Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md The parse function takes a string of Python code and returns an astroid AST. Transforms are applied by default. ```python parse(code, module_name='', path=None, apply_transforms=True) ``` -------------------------------- ### Instance.infer_binary_op Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Infers the result of a binary operation performed on an instance. ```APIDOC ## Instance.infer_binary_op(**kwargs: _P.kwargs) -> Generator[InferenceResult] ### Description Infers the result of a binary operation performed on an instance. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example - None ### Response #### Success Response (200) - Returns a generator yielding `InferenceResult` objects. ``` -------------------------------- ### Registering a Failed Import Hook Source: https://github.com/pylint-dev/astroid/blob/main/doc/extending.md Use `register_failed_import_hook` to control Astroid's behavior when an import fails. The hook should return an `astroid.Module` or raise `AstroidBuildingError`. ```python def failed_custom_import(modname): if modname != 'my_custom_module': # Don't know about this module raise AstroidBuildingError(modname=modname) return astroid.parse(''' class ThisIsAFakeClass: pass ''') MANAGER.register_failed_import_hook(failed_custom_import) ``` -------------------------------- ### astroid.unpack_infer Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md A generator that unpacks inference results. ```APIDOC ## astroid.unpack_infer(*args: _P.args, **kwargs: _P.kwargs) -> Generator[InferenceResult] ### Description A generator function that unpacks inference results. It takes arbitrary positional and keyword arguments and yields `InferenceResult` objects. ### Parameters * **args**: Positional arguments. * **kwargs**: Keyword arguments. ``` -------------------------------- ### astroid.function_to_method Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Converts a function node to a method node within a class context. ```APIDOC ## astroid.function_to_method(n, klass) ### Description Converts a given function node `n` into a method node within the context of class `klass`. ``` -------------------------------- ### getattr Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Retrieves attributes of an object, optionally considering the class context for lookup. ```APIDOC ## getattr(name: str, context: InferenceContext | None = None, lookupclass: bool = True) -> list[InferenceResult] ### Description Retrieves attributes of an object, optionally considering the class context for lookup. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example - None ### Response #### Success Response (200) - Returns a list of `InferenceResult` objects representing the found attributes. ``` -------------------------------- ### astroid.NoDefault Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Raised by function’s default_value method when an argument has no default value. ```APIDOC ## astroid.NoDefault ### Description Raised by function’s default_value method when an argument has no default value. ### Parameters * **message** (str) - Optional - The error message, defaults to '{func!r} has no default for {name!r}'. * **func** (nodes.FunctionDef | None) - Optional - Function node. * **name** (str | None) - Optional - Name of argument without a default. ### Standard attributes * **func**: Function node. * **name**: Name of argument without a default. ``` -------------------------------- ### NoDefault Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised by function's default_value method when an argument has no default value. It specifies the function and the name of the argument lacking a default. ```APIDOC ### *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) Bases: [`AstroidError`](#astroid.exceptions.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. ``` -------------------------------- ### Instance.bool_value Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Infers the truth value of an instance based on special methods like __bool__ or __len__. ```APIDOC ## Instance.bool_value(context: InferenceContext | None = None) -> bool | UninferableBase ### Description Infers the truth value for an Instance. It checks for `__bool__` (Python 3) or `__nonzero__` (Python 2) first. If not found, it checks for `__len__`. If neither is defined, all instances are considered true. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example - None ### Response #### Success Response (200) - Returns a boolean or `UninferableBase` indicating the truth value. ``` -------------------------------- ### astroid.MroError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Error raised when there is a problem with method resolution of a class. ```APIDOC ## astroid.MroError ### Description Error raised when there is a problem with method resolution of a class. ### Parameters * **message** (str) - Required - The error message. * **mros** (Iterable[Iterable[nodes.ClassDef]]) - Required - A sequence of sequences containing ClassDef nodes. * **cls** (nodes.ClassDef) - Required - ClassDef node whose MRO resolution failed. * **context** (InferenceContext | None) - Optional - InferenceContext object. ### Standard attributes * **mros**: A sequence of sequences containing ClassDef nodes. * **cls**: ClassDef node whose MRO resolution failed. * **context**: InferenceContext object. ``` -------------------------------- ### Transforming .format() to f-string Source: https://github.com/pylint-dev/astroid/blob/main/doc/extending.md This is the core AST transform function that converts a '.format()' call into an f-string. It constructs JoinedStr and FormattedValue nodes to represent the new f-string syntax. ```python def format_to_fstring_transform(node): f_string_node = astroid.JoinedStr( lineno=node.lineno, col_offset=node.col_offset, parent=node.parent, ) formatted_value_node = astroid.FormattedValue( lineno=node.lineno, col_offset=node.col_offset, parent=node.parent, ) formatted_value_node.postinit(value=node.args[0]) # Removes the {} since it will be represented as # formatted_value_node string = astroid.Const(node.func.expr.value.replace('{}', '')) f_string_node.postinit(values=[string, formatted_value_node]) return f_string_node astroid.MANAGER.register_transform( astroid.Call, format_to_fstring_transform, ) ``` -------------------------------- ### AstroidBuildingError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when astroid is unable to build a representation of a module. It includes details about the module name, any underlying error, and the source code. ```APIDOC ### *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) Bases: [`AstroidError`](#astroid.exceptions.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. ``` -------------------------------- ### Registering a transform for Call nodes Source: https://github.com/pylint-dev/astroid/blob/main/doc/extending.md This snippet registers a transform function specifically for astroid.Call nodes. The transform function is named 'format_to_fstring_transform'. ```python def format_to_fstring_transform(node): return node astroid.MANAGER.register_transform( astroid.Call, format_to_fstring_transform, ) ``` -------------------------------- ### Extracting an expression using __() Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Wrap an expression in __() to extract it. The AST will appear as if the call was never there. ```pycon >>> a = __(1) ``` -------------------------------- ### Inferring the value of a variable Source: https://github.com/pylint-dev/astroid/blob/main/doc/inference.md Use the infer() method on a node to determine its potential values. astroid can infer constant values for simple expressions. ```python >>> name_node = astroid.extract_node(''' ... a = 1 ... b = 2 ... c = a + b ... c ''') >>> inferred = next(name_node.infer()) >>> inferred >>> inferred.value 3 ``` -------------------------------- ### Extracting a default argument expression Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Use __() to wrap expressions used as default arguments, allowing their extraction. ```pycon >>> def x(d=__(foo.bar)): pass ``` -------------------------------- ### Extracting multiple nodes from code Source: https://github.com/pylint-dev/astroid/blob/main/doc/inference.md Use astroid.extract_node() with the '#@' comment to extract multiple specific nodes from a code string. Each '#@' annotation marks a line for node extraction. ```python >>> nodes = astroid.extract_node(''' ... a = 1 #@ ... b = 2 #@ ... c ''') ``` -------------------------------- ### Extracting a method definition Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Append '#@' to a method definition line to extract the method node. ```pycon >>> class X(object): >>> def meth(self): #@ >>> pass ``` -------------------------------- ### igetattr Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Provides an iterator for inferred attributes of an object. ```APIDOC ## igetattr(name: str, context: InferenceContext | None = None) -> Iterator[InferenceResult] ### Description Provides an iterator for inferred attributes of an object. This is an inferred getattr. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example - None ### Response #### Success Response (200) - Returns an iterator yielding `InferenceResult` objects. ``` -------------------------------- ### AstroidSyntaxError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when a module cannot be parsed by astroid, indicating a syntax error. ```APIDOC ### *exception* astroid.exceptions.AstroidSyntaxError(message: str, modname: str | None, error: Exception, path: str | None, source: str | None = None) Bases: [`AstroidBuildingError`](#astroid.exceptions.AstroidBuildingError) Exception class used when a module can’t be parsed. ``` -------------------------------- ### astroid.TooManyLevelsError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Exception class which is raised when a relative import was beyond the top-level. ```APIDOC ## astroid.TooManyLevelsError ### Description Exception class which is raised when a relative import was beyond the top-level. ### Parameters * **message** (str) - Optional - The error message, defaults to 'Relative import with too many levels ({level}) for module {name!r}'. * **level** (int | None) - Optional - The level which was attempted. * **name** (str | None) - Optional - The name of the module on which the relative import was attempted. ### Standard attributes * **level**: The level which was attempted. * **name**: the name of the module on which the relative import was attempted. ``` -------------------------------- ### ResolveError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Base class for astroid resolution and inference errors. It is not intended to be raised directly but serves as a foundation for more specific error types. ```APIDOC ### *exception* astroid.exceptions.ResolveError(message: str = '', context: InferenceContext | None = None, **kws: Any) Bases: [`AstroidError`](#astroid.exceptions.AstroidError) Base class of astroid resolution/inference error. ResolveError is not intended to be raised. Standard attributes: : context: InferenceContext object. ``` -------------------------------- ### TooManyLevelsError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Exception class raised when a relative import attempts to go beyond the top-level module. It includes the attempted level and the module name. ```APIDOC ### *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) Bases: [`AstroidImportError`](#astroid.exceptions.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.NameInferenceError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Raised when a name lookup fails, corresponds to NameError. ```APIDOC ## astroid.NameInferenceError ### Description Raised when a name lookup fails, corresponds to NameError. ### Parameters * **message** (str) - Optional - The error message, defaults to '{name!r} not found in {scope!r}'. * **name** (str | None) - Optional - The name for which lookup failed. * **scope** (nodes.LocalsDictNodeNG | None) - Optional - The node representing the scope in which the lookup occurred. * **context** (InferenceContext | None) - Optional - InferenceContext object. ### 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. ``` -------------------------------- ### astroid.register_module_extender Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Registers a function to extend a module with additional nodes. ```APIDOC ## astroid.register_module_extender(manager: AstroidManager, module_name: str, get_extension_mod: Callable[[], Module]) -> None ### Description Registers an extension function for a specific module with the provided `AstroidManager`. This allows dynamically adding nodes or modifying the AST of a module. ### Parameters * **manager** (AstroidManager): The AstroidManager instance to register the extender with. * **module_name** (str): The name of the module to extend. * **get_extension_mod** (Callable[[], Module]): A callable that returns a `Module` object containing the extensions. ``` -------------------------------- ### astroid.UnboundMethod Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md A special node representing a method not bound to an instance. ```APIDOC ## astroid.UnboundMethod ### Description A special node representing a method not bound to an instance. ### Parameters * **proxied** (ClassDef | FunctionDef | Lambda | [UnboundMethod](#astroid.UnboundMethod) | None) - Optional - The proxied object. ### Methods * **bool_value**(context: InferenceContext | None = None) → Literal[True] * **getattr**(name: str, context: InferenceContext | None = None) * **igetattr**(name: str, context: InferenceContext | None = None) → Iterator[InferenceResult] * **implicit_parameters**() → Literal[0, 1] * **infer_call_result**(caller: SuccessfulInferenceResult | None, context: InferenceContext | None = None) → Iterator[InferenceResult] * **is_bound**() → bool ### Special attributes * **special_attributes**: BoundMethodModel | UnboundMethodModel ``` -------------------------------- ### astroid.builtin_lookup Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Looks up a name within Python's built-in module. ```APIDOC ## astroid.builtin_lookup(name: str) -> tuple[nodes.Module, list[nodes.NodeNG]] ### Description Looks up a given name in the built-in module and returns a tuple containing the AST for the built-in module and a list of matching statements. ### Parameters * **name** (str): The name to look up in the built-in module. ### Returns A tuple containing the `nodes.Module` for the built-in module and a list of matching `nodes.NodeNG`. ``` -------------------------------- ### MroError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Error raised when there is a problem with method resolution of a class. It includes details about the MROs, the class, and the inference context. ```APIDOC ### *exception* astroid.exceptions.MroError(message: str, mros: Iterable[Iterable[nodes.ClassDef]], cls: nodes.ClassDef, context: InferenceContext | None = None, **kws: Any) Bases: [`ResolveError`](#astroid.exceptions.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. ``` -------------------------------- ### AstroidError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md The base exception class for all astroid-related exceptions. It is designed to hold structured state information. ```APIDOC ### *exception* astroid.exceptions.AstroidError(message: str = '', **kws: Any) 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. ``` -------------------------------- ### astroid.SuperError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Error raised when there is a problem with a *super* call. ```APIDOC ## astroid.SuperError ### Description Error raised when there is a problem with a *super* call. ### Parameters * **message** (str) - Required - The error message. * **super_** (objects.Super) - Required - The Super instance that raised the exception. ### Standard attributes * **super_**: The Super instance that raised the exception. * **context**: InferenceContext object. ``` -------------------------------- ### astroid.ResolveError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Base class of astroid resolution/inference error. Not intended to be raised. ```APIDOC ## astroid.ResolveError ### Description Base class of astroid resolution/inference error. ResolveError is not intended to be raised. ### Parameters * **message** (str) - Optional - The error message. * **context** (InferenceContext | None) - Optional - InferenceContext object. ### Standard attributes * **context**: InferenceContext object. ``` -------------------------------- ### DuplicateBasesError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when a class definition contains duplicate bases, indicating an inconsistency in inheritance. ```APIDOC ### *exception* astroid.exceptions.DuplicateBasesError(message: str, mros: Iterable[Iterable[nodes.ClassDef]], cls: nodes.ClassDef, context: InferenceContext | None = None, **kws: Any) Bases: [`MroError`](#astroid.exceptions.MroError) Error raised when there are duplicate bases in the same class bases. ``` -------------------------------- ### astroid.StatementMissing Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Raised when a call to node.statement() does not return a node. ```APIDOC ## astroid.StatementMissing ### Description 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(). ### Parameters * **target** (nodes.NodeNG) - Required - The node for which the parent lookup failed. ### Standard attributes * **target**: The node for which the parent lookup failed. ``` -------------------------------- ### SuperError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Error raised when there is a problem with a super() call. It includes the Super instance that caused the issue and the inference context. ```APIDOC ### *exception* astroid.exceptions.SuperError(message: str, super_: objects.Super, **kws: Any) Bases: [`ResolveError`](#astroid.exceptions.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. ``` -------------------------------- ### AstroidIndexError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when an indexable or mapping object in astroid does not contain the requested index or key. ```APIDOC ### *exception* astroid.exceptions.AstroidIndexError(message: str = '', node: nodes.NodeNG | [bases.Instance](general.md#astroid.Instance) | None = None, index: nodes.Subscript | None = None, context: InferenceContext | None = None, **kws: Any) Bases: [`AstroidError`](#astroid.exceptions.AstroidError) Raised when an Indexable / Mapping does not have an index / key. ``` -------------------------------- ### astroid.extract_node Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Parses Python code and extracts a specific AST node, supporting statement and expression extraction. ```APIDOC ## astroid.extract_node(code: str, module_name: str = '') -> NodeNG | list[NodeNG] ### Description Parses a given string of Python code as a module and extracts a designated AST node. It supports extracting specific statements by appending `#@` to a line, or arbitrary expressions by surrounding them with `__(...)`. ### Parameters * **code** (str): A piece of Python code that is parsed as a module. Will be passed through `textwrap.dedent` first. * **module_name** (str, optional): The name of the module. Defaults to ''. ### Returns The designated node from the parse tree, or a list of nodes. If no statements or expressions are selected, the last toplevel statement will be returned. If the selected statement is a discard statement, the wrapped expression is returned instead. Singleton lists are unpacked for convenience. ``` -------------------------------- ### Extracting a return statement from a nested function Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Use the '#@' suffix to extract a specific statement, like a return statement within a nested function. ```pycon >>> def x(): >>> def y(): >>> return 1 #@ ``` -------------------------------- ### InferenceOverwriteError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when an inference tip is overwritten. This exception is currently used for debugging purposes. ```APIDOC ### *exception* astroid.exceptions.InferenceOverwriteError(message: str = '', **kws: Any) Bases: [`AstroidError`](#astroid.exceptions.AstroidError) Raised when an inference tip is overwritten. Currently only used for debugging. ``` -------------------------------- ### Extracting a single node from code Source: https://github.com/pylint-dev/astroid/blob/main/doc/inference.md Use astroid.extract_node() to extract a specific node from a given code string. By default, it extracts the last node. ```python >>> node = astroid.extract_node(''' ... a = 1 ... b = 2 ... c ''') ``` -------------------------------- ### BoundMethod.infer_call_result Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Infers the result of calling a bound method, considering context for accurate inference. ```APIDOC ## BoundMethod.infer_call_result(caller: SuccessfulInferenceResult | None, context: InferenceContext | None = None) -> Iterator[InferenceResult] ### Description Infers the result of calling a bound method. It adjusts the context for calls like `object.__new__` to correctly infer arguments, especially within classmethods. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example - None ### Response #### Success Response (200) - Returns an iterator yielding `InferenceResult` objects. ``` -------------------------------- ### AstroidImportError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised specifically when a module cannot be imported by astroid. It inherits from AstroidBuildingError. ```APIDOC ### *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) Bases: [`AstroidBuildingError`](#astroid.exceptions.AstroidBuildingError) Exception class used when a module can’t be imported by astroid. ``` -------------------------------- ### NameInferenceError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when a name lookup fails, corresponding to a Python NameError. It indicates the name that was not found and the scope in which the lookup occurred. ```APIDOC ### *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) Bases: [`InferenceError`](#astroid.exceptions.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. ``` -------------------------------- ### astroid.ParentMissingError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Raised when a node which is expected to have a parent attribute is missing one. ```APIDOC ## astroid.ParentMissingError ### Description Raised when a node which is expected to have a parent attribute is missing one. ### Parameters * **target** (nodes.NodeNG) - Required - The node for which the parent lookup failed. ### Standard attributes * **target**: The node for which the parent lookup failed. ``` -------------------------------- ### InconsistentMroError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when a class's Method Resolution Order (MRO) is found to be inconsistent. ```APIDOC ### *exception* astroid.exceptions.InconsistentMroError(message: str, mros: Iterable[Iterable[nodes.ClassDef]], cls: nodes.ClassDef, context: InferenceContext | None = None, **kws: Any) Bases: [`MroError`](#astroid.exceptions.MroError) Error raised when a class’s MRO is inconsistent. ``` -------------------------------- ### NotFoundError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Alias for AttributeInferenceError, indicating that a name or attribute could not be found during inference. ```APIDOC ### astroid.exceptions.NotFoundError alias of [`AttributeInferenceError`](#astroid.exceptions.AttributeInferenceError) ``` -------------------------------- ### UnresolvableName Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Alias for NameInferenceError, indicating that a name could not be resolved within its scope. ```APIDOC ### astroid.exceptions.UnresolvableName alias of [`NameInferenceError`](#astroid.exceptions.NameInferenceError) ``` -------------------------------- ### Merge maintenance branch into main for pre-commit Source: https://github.com/pylint-dev/astroid/blob/main/doc/release.md After a patch release, merge the maintenance branch into the main branch. This ensures that `pre-commit autoupdate` functions correctly by including the patch release tag in the main branch history. ```bash git merge maintenance/X.Y.x ``` -------------------------------- ### ParentMissingError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when a node that is expected to have a parent attribute is missing one. This is crucial for navigating the AST. ```APIDOC ### *exception* astroid.exceptions.ParentMissingError(target: nodes.NodeNG) Bases: [`AstroidError`](#astroid.exceptions.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. ``` -------------------------------- ### StatementMissing Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when a call to node.statement() does not return a node, typically because a node in the chain lacks a parent attribute. ```APIDOC ### *exception* astroid.exceptions.StatementMissing(target: nodes.NodeNG) Bases: [`ParentMissingError`](#astroid.exceptions.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. ``` -------------------------------- ### InferenceError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when astroid is unable to infer a node. It provides details about the node, context, and other relevant information during the inference process. ```APIDOC ### *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) Bases: [`ResolveError`](#astroid.exceptions.ResolveError) Raised when we are unable to infer a node. Standard attributes: : node: The node inference was called on. context: InferenceContext object. ``` -------------------------------- ### AttributeInferenceError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when an attribute lookup fails, similar to Python's AttributeError. It provides details about the target and the attribute being looked up. ```APIDOC ### *exception* astroid.exceptions.AttributeInferenceError(message: str = '{attribute!r} not found on {target!r}.', attribute: str = '', target: nodes.NodeNG | [bases.BaseInstance](general.md#astroid.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) Bases: [`ResolveError`](#astroid.exceptions.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. ``` -------------------------------- ### Extracting an expression within a function call Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Expressions within function calls, like len(a), can be extracted using the __() wrapper. ```pycon >>> def foo(a, b): >>> return 0 < __(len(a)) < b ``` -------------------------------- ### infer_call_result Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Infers the result of calling a class instance. ```APIDOC ## infer_call_result(caller: SuccessfulInferenceResult | None, context: InferenceContext | None = None) -> Iterator[InferenceResult] ### Description Infers what a class instance returns when called. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example - None ### Response #### Success Response (200) - Returns an iterator yielding `InferenceResult` objects representing the call result. ``` -------------------------------- ### AstroidValueError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when a ValueError would occur in Python code, but within the context of astroid's analysis. ```APIDOC ### *exception* astroid.exceptions.AstroidValueError(message: str = '', **kws: Any) Bases: [`AstroidError`](#astroid.exceptions.AstroidError) Raised when a ValueError would be expected in Python code. ``` -------------------------------- ### AstroidTypeError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Raised when a TypeError would occur in Python code, but within the context of astroid's analysis. ```APIDOC ### *exception* astroid.exceptions.AstroidTypeError(message: str = '', node: nodes.NodeNG | [bases.Instance](general.md#astroid.Instance) | None = None, index: nodes.Subscript | None = None, context: InferenceContext | None = None, **kws: Any) Bases: [`AstroidError`](#astroid.exceptions.AstroidError) Raised when a TypeError would be expected in Python code. ``` -------------------------------- ### SuperArgumentTypeError Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/astroid.exceptions.md Alias for SuperError, indicating an issue with the arguments provided to a super() call. ```APIDOC ### astroid.exceptions.SuperArgumentTypeError alias of [`SuperError`](#astroid.exceptions.SuperError) ``` -------------------------------- ### astroid.are_exclusive Source: https://github.com/pylint-dev/astroid/blob/main/doc/api/general.md Determines if two statements are mutually exclusive, optionally considering exception handlers. ```APIDOC ## astroid.are_exclusive(stmt1, stmt2, exceptions: list[str] | None = None) -> bool ### Description Returns true if the two given statements are mutually exclusive. The `exceptions` parameter allows for specifying exception names to consider when checking if branches are within an exception handler. ### Parameters * **stmt1**: The first statement to compare. * **stmt2**: The second statement to compare. * **exceptions** (list[str] | None): An optional list of exception names to consider for mutual exclusivity checks within exception handlers. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.