Skip to content

v4.2.0b4

Pre-release
Pre-release

Choose a tag to compare

@DanielNoord DanielNoord released this 04 Jul 17:06

What's New in astroid 4.2.0b4?

Release date: 2026-07-04

  • Removed the **kwargs argument from all infer functions.
    Users upgrading their astroid versions should ensure they do no pass values other than
    context to infer.

  • Fix crash (TypeError: 'UninferableBase' object is not iterable) in the
    multiprocessing brain when a local package shadows the stdlib
    multiprocessing module.

    Closes pylint-dev/pylint#10014

  • Bound string/bytes multiplication ("x" * n) and integer left shifts
    (1 << n) in const_infer_binary_op the same way list/tuple
    multiplication and ** already are. Inferring a constant such as
    "A" * 10 ** 10 previously materialized the multi-gigabyte result
    eagerly; these operations now infer as Uninferable when the result
    would be oversized.

    Refs #3107

  • Remove the asname keyword argument from Import._infer and
    ImportFrom._infer. The alias-to-real-name translation that
    asname=True performed is now hoisted into ImportNode._infer_name,
    which runs in _infer_stmts before _infer is dispatched. Direct
    callers of Import.infer / ImportFrom.infer (previously the
    asname=False path) now consistently resolve the lookup name as-is.

    The two flows used to collapse into a single inference cache entry
    because the asname kwarg was not part of the cache key, so the
    second call returned the cached result of the first regardless of
    which one ran. With the translation hoisted upstream, the two flows
    set different lookupname values and therefore land on distinct
    cache keys, eliminating the collision.

    Refs pylint-dev/pylint#10193
    Closes #3007

  • Fix uncaught IndentationError when parsing code whose lines end in
    \r: the slice of source tokenized to compute a class or function
    position is split on \n only and could be misaligned with the AST
    line numbers. Such nodes now simply have no position information, as
    already done when tokenize raises TokenError.

    Closes #3091

  • Fix astroid bootstrap crash on PyPy 7.3.22 (TypeError: expected str, got getset_descriptor object) by also catching TypeError from
    getattr(obj, alias) in InspectBuilder.object_build. PyPy 7.3.22
    raises TypeError instead of AttributeError for unset getset
    descriptors like types.FunctionType.__text_signature__, which made
    _astroid_bootstrapping() blow up on any call into astroid.

    Refs pylint-dev/pylint#10999

  • Shorten import astroid by deferring imports only needed on cold paths.
    logging (used by modutils and raw_building solely to report
    stderr/stdout captured while importing a module) and pprint (used only
    to format debug __repr__ / repr_tree output) are now imported
    lazily, and astroid.exceptions imports astroid.typing under
    TYPE_CHECKING.

  • Fix AttributeError crash in starred_assigned_stmts when a starred
    unpacking target is an attribute (e.g. for *o.attr, x in ...) rather
    than a simple name.

    Closes #2646

  • Fix AttributeError crash in the Arguments assigned_stmts
    protocol when called without an inference context (the public
    assigned_stmts API defaults context to None). Resolving a
    function's first parameter dereferenced context.boundnode while the
    matching context and ... guard a few lines below was missing; it now
    degrades to Uninferable.

  • Fix AttributeError crash in ClassDef.infer_call_result when called
    through the public API without a context (it defaults to None) for a
    class whose metaclass defines __call__: the callee was assigned to
    context.callcontext.callee without checking that a call context exists.
    It is now guarded, matching the surrounding code.

  • Wrap assignment expressions (:=) in parentheses when emitting
    as_string output so the rendered code remains syntactically valid in
    contexts such as comparisons, where Python requires the walrus expression
    to be parenthesized.

    Closes #2668

  • Catch MemoryError/RecursionError (and ValueError) when validating
    type comments with ast.parse. Pathological type comments produced by
    fuzzers (e.g. # type: i{{{{{{{...) previously crashed parsing with a
    MemoryError or RecursionError depending on the runtime; astroid now
    treats them as invalid type comments and skips them, mirroring the f-string
    fix from #2762.

    Closes #2993

  • Fix TypeError in brain_random when random.sample is called with a
    sequence containing nodes whose __init__ does not accept lineno
    (e.g. Module). The clone helper now filters init params to those the
    class actually accepts.

    Closes #3043

  • 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 #3023
    Closes pylint-dev/pylint#10821

  • Changed block_range to consider else its own block, allowing pylint to apply
    disables to just the block.

    References pylint-dev/pylint#872

  • Fix uncaught TokenError when building a class or function whose source
    slice is malformed. tokenize.generate_tokens may raise (e.g. on an
    unterminated bracket on Python < 3.12); position computation now treats such
    a node as having no position information instead of crashing.

    Closes #2527

  • str() of a constant argument now infers the actual string value instead
    of always inferring "". When every inference path of the argument
    resolves to Const values that stringify to the same string, infer_str
    returns that string; otherwise it keeps falling back to Const("").

    Closes #2994

  • Fix AttributeError crash when looking up a special method on a class
    whose explicit metaclass infers to a non-class node (e.g. a function). Such
    a metaclass has no MRO, so the dunder lookup now raises
    AttributeInferenceError instead of crashing.

    Closes #3063

  • Fix AttributeError crash in ClassDef.getitem when __class_getitem__
    resolves to a non-callable node (e.g. an AssignName). getitem now
    raises AstroidTypeError in that case, consistent with its documented
    behaviour.

    Closes #3064

  • Fix DuplicateBasesError crash in the enum brain when inferring an enum
    class with duplicate bases (e.g. class C(enum.Enum, enum.Enum)).
    infer_enum_class now catches MroError and leaves such a malformed
    class untransformed.

    Closes #3065

  • Fix InferenceError crash in ClassDef.slots() when __slots__ is
    declared as an annotation without a value (e.g. __slots__: None). Such a
    __slots__ cannot be inferred, so slots() now returns None.

    Closes #3067

  • Fix TypeError crash in the enum brain when a functional Enum call
    has a non-string member name (e.g. Enum("e", (1,))). Such a definition
    is invalid, so inference now falls back to the default instead of crashing.

    Closes #3068

Note that this changelog also includes changes from previous betas.