github pylint-dev/astroid v4.4.0

one hour ago

What's new in astroid 4.4.0?

Release date: 2026-11-30

Breaking Changes

  • Support for Python 3.10 was dropped, along with the PY311_PLUS constant and the
    typing-extensions runtime dependency. Python 3.11 is now the minimum version.

    Closes #3375

New Features

  • t-strings (TemplateStr) are now inferred: a t-string is inferred as
    an instance of string.templatelib.Template and an interpolation field as an
    instance of string.templatelib.Interpolation. Their members are
    reconstructed from the actual template contents, so Template.strings /
    values / interpolations and Interpolation.value / expression /
    conversion / format_spec infer to the same values as at runtime,
    including inside a called function, and adding two t-strings infers to the
    concatenated template. A Template or Interpolation built by calling the
    class directly is still a plain instance with uninferable members. The
    standard library defines those classes via type(t"..."), which is not
    statically inferable, so a brain plugin rebuilds the real classes from the live
    objects. as_string now also escapes literal braces and quotes in the
    constant parts of a t-string so the rendered code round-trips.

    Closes #2789

  • Inference now narrows values through conditions joined by and and or.
    A variable tested by several constraints at once, as in
    if isinstance(apple, int) and apple != 3, keeps only the values satisfying
    every operand, and the or and negated forms are handled too. Inference stays
    conservative when an operand cannot be inferred or does not constrain the
    variable.

    Closes #2977

  • When --prefer-stubs is enabled in Pylint, .pyi stub files are now loaded
    and used during inference, and compiled extensions with an adjacent stub use
    the stub instead of runtime introspection. Stub functions whose bodies contain
    only ..., pass, or a docstring infer the return type from the annotation.

    Closes #3078

  • Inference now narrows values through the preceding operands of and and
    or. In x is not None and x, the last x no longer infers None.
    In x is None or x, the last x is only evaluated when x is None is
    false, so that condition is applied inverted. Constraints from several
    preceding operands, including nested boolean operations, are combined.

    Refs #3101
    Refs pylint-dev/pylint#1498

  • Add a brain for numpy.dtypes, whose DType classes (StringDType, Float64DType, ...) NumPy attaches at import time, so they can now be inferred. Each class gets its own constructor rather than numpy.dtype's (obj, align, copy), so pylint no longer reports no-member on them nor no-value-for-parameter / unexpected-keyword-arg on calls such as StringDType(na_object=None).

    Closes #3289
    Refs pylint-dev/pylint#9956

  • Inference now narrows values through conditions negated with not.
    not isinstance(x, int), not (x is None) and
    not (isinstance(x, int) and x == 3) used to constrain nothing; they now
    behave like the inverted condition in if statements, conditional
    expressions, comprehensions and boolean operations.

    Refs #3368
    Refs pylint-dev/pylint#8331

  • Inference now narrows values after guard statements. After
    if x is None: return, x no longer infers None, and
    assert isinstance(x, int) keeps only the int values of x for the
    code after it. An if is a guard when its body ends with return,
    raise, continue or break. An assignment between the guard and the use
    is not narrowed, and neither is a function, lambda or class defined after the
    guard.

    Refs #3369
    Closes pylint-dev/pylint#9809

  • Inference now narrows values after an if whose body assigns the name. After
    if x is None: x = [], x no longer infers the None it had before the
    if. This works for names and attributes, such as self.x or cls.x, with
    any condition that inference already narrows on.

    Refs #3387
    Closes pylint-dev/pylint#5085
    Closes pylint-dev/pylint#4121
    Closes pylint-dev/pylint#3045
    Closes pylint-dev/pylint#2855

  • Inference now narrows values with callable(x) conditions. After
    if callable(x):, x no longer infers values that cannot be called, and
    after if not callable(x): it no longer infers values that can.

    Refs #3391
    Refs pylint-dev/pylint#1493

Bug Fixes

  • Keep applying subsequent transforms when a transform returns None, preserving
    the current node instead of stopping the transform chain.

    Closes #809

  • Infer list augmented concatenation with a tuple as a list, rather than Uninferable.

    Closes #1865

  • dataclass_transform() now always returns the transformed ClassDef node so
    subsequent Enum inference still populates __members__ on @dataclass(init=False)
    and custom-__init__ enum classes.

    Refs #2317

  • Add support for NumPy 2.x, fixing false positives when analyzing
    code that uses NumPy 2.

    Closes #2710

  • dataclasses.replace(obj, ...) is now inferred as an instance of obj's own
    class instead of being inferred through the stdlib body of replace(). That body
    resolves obj.__class__ through the metaclass chain, which fails when a base is a
    subscripted generic such as Base[T]: the call became Uninferable with the
    old-style Generic[T] syntax, and resolved to the wrong class with PEP 695
    class Base[T] syntax. The concrete caller type is now propagated correctly,
    including through Self-annotated method chains.

    Refs #3061

  • Fix inference of callable instances stored as attributes, including attributes
    with a same-named member on the callable. Infer the result of calling the
    instance instead of looking up the attribute name on it again.

    Refs #3077

  • modutils.get_source_file no longer returns a compiled module as if it were
    source. Bytecode (.pyc/.pyo) and binary extension modules
    (.so/.pyd/.dll) now fall through to the regular stub/source lookup,
    so a .pyi stub sitting next to a compiled module is found again instead of
    the compiled file being handed back and then parsed as source.

    Closes #3087

  • Require a C extension to be located in the standard library before its
    standard library name allows it to be imported. A name such as colorsys
    was trusted on its own, so an extension of that name sitting next to the
    analysed sources was imported, and its module initialisation run, without
    being on extension-pkg-allow-list. Extensions shipped with the
    interpreter are unaffected.

    Refs #3193

  • Do not infer a functional Enum whose class name is not a string. Such a
    definition is invalid at runtime and could expose a non-string class name to
    consumers.

    Refs #3212
    Refs pylint-dev/pylint#11229

  • modutils.module_in_path no longer reports a module as living under a
    directory when its path only shares a leading name with that directory, such as
    a module in proj_extra matching the path proj. It now uses the same
    separator-aware containment check as _get_relative_base_path.

    Refs #3223

  • as_string() no longer renders an f-string whose delimiter reappears
    unescaped in its body. Such an f-string terminated early and either failed to
    parse or reparsed to a different expression, which matters because
    brain_dataclasses and brain_namedtuple_enum reparse as_string()
    output.

    Refs #3235

  • as_string() no longer raises ValueError on an integer constant too
    large to repr() (past sys.get_int_max_str_digits()); such integers are
    rendered as hex literals instead. This crashed the dataclass transform when a
    field was shadowed by a property returning e.g. 10 ** 5000.

    Refs #3236

  • The fallback __new__ of the object model, used when the real one cannot be found
    (instance.__new__, super().__new__(cls) under an uninferable ancestor, or the
    __new__ of a C type outside builtins), now has the signature
    (cls, *args, **kwargs) instead of (self, cls). Since __new__ takes the
    class explicitly, the old signature reported the class argument as missing and any
    other argument as unexpected.

    Closes #3237
    Closes pylint-dev/pylint#8325
    Refs pylint-dev/pylint#10670

  • Fix a crash when inferring a super() call inside a function that is decorated
    with @classmethod but is not defined inside a class.

    Refs #3240
    Closes pylint-dev/pylint#8755

  • AsStringVisitor no longer lets a docstring break out of the triple-quoted
    literal it is rendered into. A docstring value containing """, ending in a
    quote, or holding a NUL byte previously closed the literal early or, through the
    DOC_NEWLINE sentinel, injected extra lines into as_string() output, which
    the dataclass and namedtuple brains reparse. Such values now fall back to
    repr so the output round-trips.

    Refs #3249

  • Infer a str/bytes old-style % interpolation without crashing when a
    %c conversion receives an out-of-range code point, such as "%c" % 0x110000
    or b"%c" % 256. The evaluation now catches OverflowError and yields
    Uninferable, matching the other invalid interpolations.

    Refs #3254

  • Infer an enum member whose integer value is past the int-to-str conversion
    limit, such as A = 0xff... (a large hex literal the tokenizer accepts).

    Refs #3256

  • Fix an AttributeError crash when inferring a typing.NamedTuple subclass
    or an enum.Enum whose body contains an assignment target that is not a plain
    name, such as the annotation a.b: str or the chained assignment x = a.b = 1.
    Such targets do not name a field or member and are now skipped.

    Closes #3257

  • brain_gi only imports gi for a bare require_version(...) call when the
    name actually resolves to gi, no longer for an unrelated function of that name.

    Refs #3277

  • The numpy brain no longer imports numpy to find out its version but reads
    from the installed package metadata instead.

    Refs #3308

  • Fix an IndexError crash when inferring a functional enum.Enum call
    whose member list contains an empty tuple, such as enum.Enum("E", [()]).
    Such an invalid member now degrades to Uninferable instead of raising.

    Refs #3332

  • Fix TypeError in FunctionDef.infer_call_result for a function named
    with_metaclass when the caller is a function, such as the decorator's
    parent while inferring FunctionDef.type.

    Closes #3336

  • A class attribute is now inferred with the values assigned to it through the
    class in the module that defines it, as in cls.attr = value in a class
    method or Klass.attr = value, along with the value set in the class body.
    Only the latter used to be inferred, so pylint reported
    unsubscriptable-object, unsupported-membership-test and similar errors
    on lazily initialized class attributes such as cache = None. A value
    assigned to an attribute of a parent class also no longer leaks into a
    subclass that assigns the same attribute in the same scope.

    Refs #3351
    Closes pylint-dev/pylint#9250
    Closes pylint-dev/pylint#9809
    Closes pylint-dev/pylint#10082
    Refs pylint-dev/pylint#3045

  • Fix an AssertionError when inferring a namedtuple, or a class derived from
    typing.NamedTuple, if collections.namedtuple itself cannot be inferred.
    The namedtuple is now built as if rename=False.

    Refs #3352

  • Fix TypeError in ClassDef.ancestors() when typing.Tuple or
    typing.Callable is first inferred with an exhausted inference context.
    The synthesized class was built with an uninferable base and reused for
    every later inference.

    Closes #3366

  • Fix a crash when inferring an attribute that resolves to a method proxying
    something other than a function.

    Refs #3370
    Refs pylint-dev/pylint#10345

  • Add a name to Slice nodes, giving "slice" like other inferred builtin
    values (Const, List, Dict...) give the name of their type. A slice
    object used as a class base, metaclass, exception or super() argument no longer
    crashes code that reads the name of an inferred value.

    Unknown nodes now have a pytype() too, like their name and qname(),
    so every value inference returns can be asked for its name, qualified name and type.

    Refs #3373
    Refs pylint-dev/pylint#11609

  • Infer the name bound by a type statement as a typing.TypeAliasType
    instance instead of the aliased value, so __value__ and the other alias
    attributes are found on it.

    Refs #3374
    Refs pylint-dev/pylint#10091

  • Fix an uncaught TypeError when inferring a starred name nested in a
    for target, such as for a, (b, *c) in ..., over an element the
    inference cannot see into.

    Closes #3378

  • Do not cache inference results that were truncated by the inference budget.
    Caching them made inference results depend on the order in which modules were analysed.

    Closes #3383
    Closes #3464
    Closes pylint-dev/pylint#11582
    Refs pylint-dev/pylint#9549

    Thanks to @budhitha for the astroid-only reproducer behind #3464.

  • Prevent a TypeError in infer_typing_alias when _alias() is called with
    a non-integer constant second argument.

    Closes #3389

  • Source files are now closed when reading fails during module building.

    Closes #3404

  • FunctionDef.getattr() and Lambda.getattr() no longer add the special
    attribute to instance_attrs when an attribute such as __name__ is both
    assigned on the function and a special attribute. The stored list used to grow by
    one on every lookup. ClassDef.repr_tree(ast_state=True) no longer raises
    AttributeError.

    Refs #3411

  • Fix a crash when inferring len() on an instance whose __len__ is not
    callable, such as a module. The call is now uninferable instead.

    Refs #3426

  • Fix AttributeError when calling qname() on a generator expression or a
    list, set or dict comprehension. They are now named <genexpr>, <listcomp>,
    <setcomp> and <dictcomp>, like <lambda>, which also shows in their repr.

    Refs #3427

  • Stop inferring a __get__ attribute on generators, which are not
    descriptors. Accessing it is now reported as no-member, like the
    AttributeError at runtime, instead of crashing attribute inference.

    Refs #3428

  • Fix AttributeError when inferring the call result of a subclass of
    type without a caller.

    Refs #3429

  • ClassDef.has_dynamic_getattr() now always returns a bool. It returned
    Uninferable when the __getattr__ of a metaclass could not be inferred.

    Refs #3430

  • modpath_from_file() no longer raises ImportError for a module inside a namespace
    package that also exists in site-packages: the namespace package is now looked up from
    the directory the module is resolved from.

    Refs #3445
    Refs pylint-dev/pylint#10278

  • Fixed isinstance() and issubclass() inference constraint when the classinfo is a
    PEP 604 union, e.g. isinstance(x, int | str).

    Refs #3453

  • Apply the !s, !r and !a conversions when inferring f-strings, so
    f'{"a"!r}' is inferred as "'a'" instead of 'a'.

    Refs #3461

  • Infer names bound by an import in an enum class body as enum members, like
    assigned names, instead of as the plain imported object.

    Refs #3466
    Closes pylint-dev/pylint#10951

  • Do not treat values wrapped in enum.nonmember() as members of the enum.
    They were listed in __members__, so pylint reported invalid-enum-extension
    when such a class was extended, for example on any Django 6 models.Choices
    subclass.

    Closes #3467
    Refs pylint-dev/pylint#6887

  • Fix a hang when inferring a class whose __bool__ reads attributes that are
    narrowed by a truthiness guard (if self.left:). The truthiness constraint
    now passes the inference context to bool_value(), so the recursion guard
    applies.

    Refs #3473
    Closes pylint-dev/pylint#11807

  • Only treat a function as a property because of its decorator's name, like
    @lazy or @reify, when the function is defined in a class body. A
    function decorated this way elsewhere stays a function, so it is no longer
    inferred as a property object that is not callable.

    Refs #3475
    Closes pylint-dev/pylint#3586

  • typing.NamedTuple is now inferred as a tuple subclass with _asdict,
    _replace, _fields, _make and _field_defaults, as typeshed
    declares it. self in a method of a typing.NamedTuple subclass finds that
    API and the tuple methods such as count and index through it, so pylint
    no longer reports no-member, unsubscriptable-object or
    not-an-iterable on self there.

    Refs #3476
    Closes pylint-dev/pylint#7891

  • The ctypes brain now gives the value argument of c_int, c_char,
    c_double and the other simple types the same default as at runtime
    (0, 0.0, b"\x00", "\x00" or False). apple = c_int() no
    longer makes pylint emit no-value-for-parameter on interpreters where
    _ctypes is a built-in module, such as the uv and python-build-standalone
    builds.

    Refs #3482

  • Fix a false positive for functools.partial objects stored as class attributes: before Python 3.14, accessing one through an instance does not bind self, and astroid no longer infers a bound method for it.

    Refs #3491
    Closes pylint-dev/pylint#2271

Other Changes

  • A RecursionError raised while parsing a file is now enriched with a note
    naming the file that could not be parsed, and advising to raise the recursion
    limit (from pylint: --init-hook='import sys; sys.setrecursionlimit(2000)').

    Closes #2974

Internal Changes

  • Remove register_builtin_transform from astroid.brain.brain_builtin_inference.
    It was only meant for astroid's own builtin brain, which now declares its inference
    functions in a static dispatch table.

    Refs #1115

  • The changelog is now assembled by towncrier from news fragments in
    doc/whatsnew/fragments/, like in pylint. Add a <issue>.<type> fragment
    there instead of editing a changelog file.

    Closes #3209

Performance Improvements

  • Collapse the 19 builtin inference transforms into a single dispatcher
    transform on nodes.Call. The transform visitor previously ran 19
    predicates per Call node, each repeating the same isinstance checks;
    the dispatcher does them once and routes by name via a dict.

    Refs #1115

Don't miss a new astroid release

NewReleases is sending notifications on new releases.