astroid
An abstract syntax tree for Python with inference support.
Description
Astroid ======= .. image:: https://codecov.io/gh/pylint-dev/astroid/branch/main/graph/badge.svg :target: https://codecov.io/gh/pylint-dev/astroid :alt: Coverage badge from codecov .. image:: https://readthedocs.org/projects/astroid/badge/?version=latest :target: http://astroid.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/ambv/black .. image:: https://results.pre-commit.ci/badge/github/pylint-dev/astroid/main.svg :target: https://results.pre-commit.ci/latest/github/pylint-dev/astroid/main :alt: pre-commit.ci status .. |tidelift_logo| image:: https://raw.githubusercontent.com/pylint-dev/astroid/main/doc/media/Tidelift_Logos_RGB_Tidelift_Shorthand_On-White.png :width: 200 :alt: Tidelift .. list-table:: :widths: 10 100 * - |tidelift_logo| - Professional support for astroid is available as part of the `Tidelift Subscription`_. Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools. .. _Tidelift Subscription: https://tidelift.com/subscription/pkg/pypi-astroid?utm_source=pypi-astroid&utm_medium=referral&utm_campaign=readme What's this? ------------ The aim of this module is to provide a common base representation of python source code. It is currently the library powering pylint's capabilities. It provides a compatible representation which comes from the `_ast` module. It rebuilds the tree generated by the builtin _ast module by recursively walking down the AST and building an extended ast. The new node classes have additional methods and attributes for different usages. They include some support for static inference and local name scopes. Furthermore, astroid can also build partial trees by inspecting living objects. Installation ------------ Extract the tarball, jump into the created directory and run:: pip install . If you want to do an editable installation, you can run:: pip install -e . If you have any questions, please mail the code-quality@python.org mailing list for support. See http://mail.python.org/mailman/listinfo/code-quality for subscription information and archives. Documentation ------------- http://astroid.readthedocs.io/en/latest/ Python Versions --------------- astroid 2.0 is currently available for Python 3 only. If you want Python 2 support, use an older version of astroid (though note that these versions are no longer supported). Test ---- Tests are in the 'test' subdirectory. To launch the whole tests suite, you can use either `tox` or `pytest`:: tox pytest
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 4.1.2 | Imported from PyPI (4.1.2) | Low | 4/21/2026 |
| v4.2.0b1 | What's New in astroid 4.2.0b1? ============================ Release date: Release date: 2026-03-23 * Changed `block_range` to consider `else` its own block, allowing `pylint` to apply disables to just the block. References pylint-dev/pylint#872 | Medium | 3/23/2026 |
| v4.1.2 | What's New in astroid 4.1.2? ============================ Release date: 2026-03-22 * Fix crash accessing property `fset` in generic classes with type annotations. Closes #2996 * Fix infinite recursion caused by cyclic inference in ``Constraint``. * Fix ``RecursionError`` in ``_compute_mro()`` when circular class hierarchies are created through runtime name rebinding. Circular bases are now resolved to the original class instead of recursing. Closes #2967 Closes pyli | Low | 3/22/2026 |
| v4.1.1 | What's New in astroid 4.1.1? ============================ Release date: 2026-02-22 * Let `UnboundMethodModel` inherit from `FunctionModel` to improve inference of dunder methods for unbound methods. Refs #2741 * Filter ``Unknown`` from ``UnboundMethod`` and ``Super`` special attribute lookup to prevent placeholder nodes from leaking during inference. Refs #2741 | Low | 2/23/2026 |
| v4.1.0 | What's New in astroid 4.1.0? ============================ Release date: 2026-02-08 * Add support for equality constraints (``==``, ``!=``) in inference. Closes pylint-dev/pylint#3632 Closes pylint-dev/pylint#3633 * Ensure ``ast.JoinedStr`` nodes are ``Uninferable`` when the ``ast.FormattedValue`` is ``Uninferable``. This prevents ``unexpected-keyword-arg`` messages in Pylint where the ``Uninferable`` string appeared in function arguments that were constructed dynamically. | Low | 2/9/2026 |
| v4.0.4 | What's New in astroid 4.0.4? ============================ Release date: 2026-02-07 * Fix ``is_namespace()`` crash when search locations contain ``pathlib.Path`` objects. Closes #2942 | Low | 2/7/2026 |
| v4.0.3 | What's New in astroid 4.0.3? ============================ Release date: 2026-01-03 * Fix inference of ``IfExp`` (ternary expression) nodes to avoid prematurely narrowing results in the face of inference ambiguity. Closes #2899 * Fix base class inference for dataclasses using the PEP 695 typing syntax. Refs pylint-dev/pylint#10788 | Low | 1/3/2026 |
| v4.0.2 | What's New in astroid 4.0.2? ============================ Release date: 2025-11-09 * Handle FunctionDef blockstart_tolineno edge cases correctly. Refs #2880 * Add ``HTTPMethod`` enum support to brain module for Python 3.11+. Refs pylint-dev/pylint#10624 Closes #2877 | Low | 11/9/2025 |
| v4.0.1 | What's New in astroid 4.0.1? ============================ Release date: 2025-10-11 * Suppress ``SyntaxWarning`` for invalid escape sequences and return in finally on Python 3.14 when parsing modules. * Assign ``Import`` and ``ImportFrom`` nodes to module locals if used with ``global``. Closes pylint-dev/pylint#10632 | Low | 10/11/2025 |
| v4.0.0 | What's New in astroid 4.0.0? ============================ Release date: 2025-10-05 * Support constraints from ternary expressions in inference. Closes pylint-dev/pylint#9729 * Handle deprecated `bool(NotImplemented)` cast in const nodes. * Add support for boolean truthiness constraints (`x`, `not x`) in inference. Closes pylint-dev/pylint#9515 * Fix false positive `invalid-name` on `attrs` classes with `ClassVar` annotated variables. Closes pylint-dev/pylint#10525 | Low | 10/5/2025 |
| v4.0.0rc0 | Release v4.0.0rc0 | Low | 9/29/2025 |
| v4.0.0b3 | v4.0.0b3 | Low | 9/22/2025 |
| v4.0.0b2 | Release v4.0.0b2 | Low | 8/7/2025 |
| v4.0.0b1 | Release v4.0.0b1 | Low | 8/6/2025 |
| v4.0.0b0 | * Removed internal functions ``infer_numpy_member``, ``name_looks_like_numpy_member``, and ``attribute_looks_like_numpy_member`` from ``astroid.brain.brain_numpy_utils``. * To alleviate circular imports, the ``manager`` argument to ``AstroidBuilder()`` is now required. * Constants now have a parent of ``nodes.SYNTHETIC_ROOT``. * Fix crashes with large positive and negative list multipliers. Closes #2521 Closes #2523 * Fix precedence of `path` arg in `modpath_from_file_with | Low | 7/27/2025 |
| v3.3.11 | * Fix a crash when parsing an empty arbitrary expression with ``extract_node`` (``extract_node("__()")``). Closes #2734 * Fix a crash when parsing a slice called in a decorator on a function that is also decorated with a known ``six`` decorator. Closes #2721 | Low | 7/13/2025 |
| v3.3.10 | * Avoid importing submodules sharing names with standard library modules. Closes #2684 * Fix bug where ``pylint code.custom_extension`` would analyze ``code.py`` or ``code.pyi`` instead if they existed. Closes pylint-dev/pylint#3631 | Low | 5/10/2025 |
| v3.3.9 | What's New in astroid 3.3.9? ============================ Release date: 2025-03-09 * Fix crash when `sys.modules` contains lazy loader objects during checking. Closes #2686 Closes pylint-dev/pylint#8589 * Upload release assets to PyPI via Trusted Publishing. Refs pylint-dev/pylint#10256 | Low | 3/9/2025 |
| v4.0.0a0 | * Removed internal functions ``infer_numpy_member``, ``name_looks_like_numpy_member``, and ``attribute_looks_like_numpy_member`` from ``astroid.brain.brain_numpy_utils``. * To alleviate circular imports, the ``manager`` argument to ``AstroidBuilder()`` is now required. * Constants now have a parent of ``nodes.SYNTHETIC_ROOT``. * Fix crashes with large positive and negative list multipliers. Closes #2521 Closes #2523 * Fix precedence of `path` arg in `modpath_from_file_with | Low | 2/3/2025 |
| v3.3.8 | What's New in astroid 3.3.8? ============================ Release date: 2024-12-23 * Fix inability to import `collections.abc` in python 3.13.1. The reported fixes in astroid 3.3.6 and 3.3.7 did not actually fix this issue. Closes pylint-dev/pylint#10112 | Low | 12/24/2024 |
| v3.3.7 | What's New in astroid 3.3.7? ============================ Release date: 2024-12-21 * Fix inability to import `collections.abc` in python 3.13.1. The reported fix in astroid 3.3.6 did not actually fix this issue. Closes pylint-dev/pylint#10112 | Low | 12/21/2024 |
| v3.3.6 | What's New in astroid 3.3.6? ============================ Release date: 2024-12-08 * Fix inability to import `collections.abc` in python 3.13.1. Closes pylint-dev/pylint#10112 * Fix crash when typing._alias() call is missing arguments. Closes #2513 | Low | 12/8/2024 |
| v3.3.5 | What's New in astroid 3.3.5? ============================ Release date: 2024-10-04 * Control setting local nodes outside of the supposed local's constructor. Closes #1490 * Fix Python 3.13 compatibility re: `collections.abc` Closes pylint-dev/pylint#10000 | Low | 10/4/2024 |
| v3.3.4 | What's New in astroid 3.3.4? ============================ Release date: 2024-09-23 * Fix regression with f-string inference. Closes pylint-dev/pylint#9947 * Fix bug with ``manager.clear_cache()`` not fully clearing cache Refs https://github.com/pylint-dev/pylint/pull/9932#issuecomment-2364985551 * Fix a crash from inferring empty format specs. Closes pylint-dev/pylint#9945 | Low | 9/23/2024 |
| v3.3.3 | What's New in astroid 3.3.3? ============================ Release date: 2024-09-20 * Fix inference regression with property setters. Closes pylint-dev/pylint#9811 * Add annotation-only instance attributes to attrs classes to fix `no-member` false positives. Closes #2514 | Low | 9/20/2024 |
| v3.3.2 | What's New in astroid 3.3.2? ============================ Release date: 2024-08-11 * Restore support for soft-deprecated members of the ``typing`` module with python 3.13. Refs pylint-dev/pylint#9852 | Low | 8/11/2024 |
| v3.3.1 | What's New in astroid 3.3.1? ============================ Release date: 2024-08-06 * Fix a crash introduced in 3.3.0 involving invalid format strings. Closes #2492 | Low | 8/6/2024 |
| v3.3.0 | What's New in astroid 3.3.0? ============================ Release date: 2024-08-04 * Add support for Python 3.13. * Remove support for Python 3.8 (and constants `PY38`, `PY39_PLUS`, and `PYPY_7_3_11_PLUS`). Refs #2443 * Add the ``__annotations__`` attribute to the ``ClassDef`` object model. Closes pylint-dev/pylint#7126 * Implement inference for JoinedStr and FormattedValue * Add support for ``ssl.OP_LEGACY_SERVER_CONNECT`` (new in Python 3.12). Closes pylint-dev/ | Low | 8/4/2024 |
| v3.2.4 | What's New in astroid 3.2.4? ============================ Release date: 2024-07-20 * Avoid reporting unary/binary op type errors when inference is ambiguous. Closes #2467 | Low | 7/20/2024 |
| v3.2.3 | What's New in astroid 3.2.3? ============================ Release date: 2024-07-11 * Fix ``AssertionError`` when inferring a property consisting of a partial function. Closes pylint-dev/pylint#9214 | Low | 7/11/2024 |
| v3.2.2 | What's New in astroid 3.2.2? ============================ Release date: 2024-05-20 * Improve inference for generic classes using the PEP 695 syntax (Python 3.12). Refs pylint-dev/pylint#9406 | Low | 5/19/2024 |
| v3.2.1 | What's New in astroid 3.2.1? ============================ Release date: 2024-05-16 * Fix ``RecursionError`` in ``infer_call_result()`` for certain ``__call__`` methods. Closes pylint-dev/pylint#9139 * Add ``AstroidManager.prefer_stubs`` attribute to control the astroid 3.2.0 feature that prefers stubs. Refs pylint-dev/pylint#9626 Refs pylint-dev/pylint#9623 | Low | 5/16/2024 |
| v3.2.0 | * ``.pyi`` stub files are now preferred over ``.py`` files when resolving imports, (except for numpy). Closes pylint-dev/pylint#9185 * ``igetattr()`` returns the last same-named function in a class (instead of the first). This avoids false positives in pylint with ``@overload``. Closes #1015 Refs pylint-dev/pylint#4696 * Adds ``module_denylist`` to ``AstroidManager`` for modules to be skipped during AST generation. Modules in this list will cause an ``AstroidImportError` | Low | 5/7/2024 |
| v3.1.0 | * Include PEP 695 (Python 3.12) generic type syntax nodes in ``get_children()``, allowing checkers to visit them. Refs pylint-dev/pylint#9193 * Add ``__main__`` as a possible inferred value for ``__name__`` to improve control flow inference around ``if __name__ == "__main__":`` guards. Closes #2071 * Following a deprecation period, the ``names`` arg to the ``Import`` constructor and the ``op`` arg to the ``BoolOp`` constructor are now required, and the ``doc`` args to the ``P | Low | 2/23/2024 |
| v3.0.3 | * Fix type of ``UnicodeDecodeError.object`` inferred as ``str`` instead of ``bytes``. Closes pylint-dev/pylint#9342 * Fix ``no-member`` false positives for ``args`` and ``kwargs`` on ``ParamSpec`` under Python 3.12. Closes pylint-dev/pylint#9401 | Low | 2/4/2024 |
| v3.0.2 | What's New in astroid 3.0.2? ============================ Release date: 2023-12-12 * Avoid duplicate inference results for some uses of ``typing.X`` constructs like ``Tuple[Optional[int], ...]``. This was causing pylint to occasionally omit messages like ``deprecated-typing-alias``. Closes pylint-dev/pylint#9220 | Low | 12/12/2023 |
| v3.0.1 | * Fix crashes linting code using PEP 695 (Python 3.12) generic type syntax. Closes pylint-dev/pylint#9098 | Low | 10/16/2023 |
| v3.0.0 | * Add support for Python 3.12, including PEP 695 type parameter syntax. Closes #2201 * Remove support for Python 3.7. Refs #2137 * Use the global inference cache when inferring, even without an explicit ``InferenceContext``. This is a significant performance improvement given how often methods default to ``None`` for the context argument. (Linting ``astroid`` itself now takes ~5% less time on Python 3.12; other projects requiring more complex inference calculations wi | Low | 9/26/2023 |
| v2.15.8 | * Fix a regression in 2.15.7 for `unsubscriptable-object`. Closes #2305 Closes pylint-dev/pylint#9069 | Low | 9/26/2023 |
| v3.0.0b0 | Pre-release for astroid 3.0.0, with API deprecation applied. | Low | 9/24/2023 |
| v2.15.7 | * Fix a crash when inferring a ``typing.TypeVar`` call. Closes pylint-dev/pylint#8802 * Infer user-defined enum classes by checking if the class is a subtype of ``enum.Enum``. Closes pylint-dev/pylint#8897 * Fix inference of functions with ``@functools.lru_cache`` decorators without parentheses. Closes pylint-dev/pylint#8868 * Make ``sys.argv`` uninferable because it never is. (It's impossible to infer the value it will have outside of static analysis where it's our | Low | 9/23/2023 |
| v3.0.0a9 | Pre-release for astroid 3.0.0, with performance improvements, fixes for Python 3.12 compatibility, and an improvement to `Arguments.arguments()`, among other changes. See the [full list of changes](https://github.com/pylint-dev/astroid/blob/v3.0.0a9/ChangeLog). | Low | 8/6/2023 |
| v3.0.0a8 | Pre-release for astroid 3.0.0, for https://github.com/pylint-dev/astroid/pull/2250 and python 3.12 in pylint. For a full list of changes see https://github.com/pylint-dev/astroid/blob/v3.0.0a8/ChangeLog | Low | 7/15/2023 |
| v2.15.6 | * Harden ``get_module_part()`` against ``"."``. Closes pylint-dev/pylint#8749 * Avoid expensive list/tuple multiplication operations that would result in ``MemoryError``. Closes pylint-dev/pylint#8748 | Low | 7/8/2023 |
| v3.0.0a7 | This is the seventh pre-release for astroid 3.0.0, main change is added Try node. For a full list of changes see https://github.com/pylint-dev/astroid/blob/v3.0.0a7/ChangeLog | Low | 7/8/2023 |
| v3.0.0a6 | This is the sixth pre-release for astroid 3.0.0, main change is the python 3.12 support. For a full list of changes see https://github.com/pylint-dev/astroid/blob/v3.0.0a6/ChangeLog | Low | 7/4/2023 |
| v3.0.0a5 | This is the fifth pre-release for astroid 3.0.0. For a full list of changes see https://github.com/pylint-dev/astroid/blob/v3.0.0a5/ChangeLog | Low | 6/13/2023 |
| v3.0.0a4 | This is the fourth pre-release for astroid 3.0.0. For a full list of changes see https://github.com/pylint-dev/astroid/blob/v3.0.0a4/ChangeLog | Low | 6/6/2023 |
| v3.0.0a3 | This is the third pre-release for astroid 3.0.0. For a full list of changes see https://github.com/pylint-dev/astroid/blob/v3.0.0a3/ChangeLog | Low | 5/14/2023 |
| v2.15.5 | * Handle ``objects.Super`` in ``helpers.object_type()``. Refs pylint-dev/pylint#8554 | Low | 5/14/2023 |
| v3.0.0a2 | This is the second pre-release for astroid 3.0.0. For a full list of changes see https://github.com/pylint-dev/astroid/blob/v3.0.0a1/ChangeLog | Low | 4/25/2023 |
