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_PLUSconstant and the
typing-extensionsruntime 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 ofstring.templatelib.Templateand an interpolation field as an
instance ofstring.templatelib.Interpolation. Their members are
reconstructed from the actual template contents, soTemplate.strings/
values/interpolationsandInterpolation.value/expression/
conversion/format_specinfer to the same values as at runtime,
including inside a called function, and adding two t-strings infers to the
concatenated template. ATemplateorInterpolationbuilt by calling the
class directly is still a plain instance with uninferable members. The
standard library defines those classes viatype(t"..."), which is not
statically inferable, so a brain plugin rebuilds the real classes from the live
objects.as_stringnow 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
andandor.
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 theorand negated forms are handled too. Inference stays
conservative when an operand cannot be inferred or does not constrain the
variable.Closes #2977
-
When
--prefer-stubsis enabled in Pylint,.pyistub 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
andand
or. Inx is not None and x, the lastxno longer infersNone.
Inx is None or x, the lastxis only evaluated whenx is Noneis
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 thannumpy.dtype's(obj, align, copy), so pylint no longer reportsno-memberon them norno-value-for-parameter/unexpected-keyword-argon calls such asStringDType(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 inifstatements, 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,xno longer infersNone, and
assert isinstance(x, int)keeps only theintvalues ofxfor the
code after it. Anifis a guard when its body ends withreturn,
raise,continueorbreak. 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
ifwhose body assigns the name. After
if x is None: x = [],xno longer infers theNoneit had before the
if. This works for names and attributes, such asself.xorcls.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):,xno longer infers values that cannot be called, and
afterif 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 transformedClassDefnode so
subsequentEnuminference 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 ofobj's own
class instead of being inferred through the stdlib body ofreplace(). That body
resolvesobj.__class__through the metaclass chain, which fails when a base is a
subscripted generic such asBase[T]: the call becameUninferablewith the
old-styleGeneric[T]syntax, and resolved to the wrong class with PEP 695
class Base[T]syntax. The concrete caller type is now propagated correctly,
including throughSelf-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_fileno 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.pyistub 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 ascolorsys
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 onextension-pkg-allow-list. Extensions shipped with the
interpreter are unaffected.Refs #3193
-
Do not infer a functional
Enumwhose 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_pathno longer reports a module as living under a
directory when its path only shares a leading name with that directory, such as
a module inproj_extramatching the pathproj. 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_dataclassesandbrain_namedtuple_enumreparseas_string()
output.Refs #3235
-
as_string()no longer raisesValueErroron an integer constant too
large torepr()(pastsys.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 outsidebuiltins), 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@classmethodbut is not defined inside a class.Refs #3240
Closes pylint-dev/pylint#8755 -
AsStringVisitorno 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_NEWLINEsentinel, injected extra lines intoas_string()output, which
the dataclass and namedtuple brains reparse. Such values now fall back to
reprso the output round-trips.Refs #3249
-
Infer a
str/bytesold-style%interpolation without crashing when a
%cconversion receives an out-of-range code point, such as"%c" % 0x110000
orb"%c" % 256. The evaluation now catchesOverflowErrorand yields
Uninferable, matching the other invalid interpolations.Refs #3254
-
Infer an
enummember whose integer value is past the int-to-str conversion
limit, such asA = 0xff...(a large hex literal the tokenizer accepts).Refs #3256
-
Fix an
AttributeErrorcrash when inferring atyping.NamedTuplesubclass
or anenum.Enumwhose body contains an assignment target that is not a plain
name, such as the annotationa.b: stror the chained assignmentx = a.b = 1.
Such targets do not name a field or member and are now skipped.Closes #3257
-
brain_gionly importsgifor a barerequire_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
numpyto find out its version but reads
from the installed package metadata instead.Refs #3308
-
Fix an
IndexErrorcrash when inferring a functionalenum.Enumcall
whose member list contains an empty tuple, such asenum.Enum("E", [()]).
Such an invalid member now degrades toUninferableinstead of raising.Refs #3332
-
Fix
TypeErrorinFunctionDef.infer_call_resultfor a function named
with_metaclasswhen the caller is a function, such as the decorator's
parent while inferringFunctionDef.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 incls.attr = valuein a class
method orKlass.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-testand similar errors
on lazily initialized class attributes such ascache = 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
AssertionErrorwhen inferring a namedtuple, or a class derived from
typing.NamedTuple, ifcollections.namedtupleitself cannot be inferred.
The namedtuple is now built as ifrename=False.Refs #3352
-
Fix
TypeErrorinClassDef.ancestors()whentyping.Tupleor
typing.Callableis 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
nametoSlicenodes, giving"slice"like other inferred builtin
values (Const,List,Dict...) give the name of their type. Aslice
object used as a class base, metaclass, exception orsuper()argument no longer
crashes code that reads the name of an inferred value.Unknownnodes now have apytype()too, like theirnameandqname(),
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
typestatement as atyping.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
TypeErrorwhen inferring a starred name nested in a
fortarget, such asfor 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#9549Thanks to @budhitha for the astroid-only reproducer behind #3464.
-
Prevent a
TypeErrorininfer_typing_aliaswhen_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()andLambda.getattr()no longer add the special
attribute toinstance_attrswhen 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
AttributeErrorwhen callingqname()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 asno-member, like the
AttributeErrorat runtime, instead of crashing attribute inference.Refs #3428
-
Fix
AttributeErrorwhen inferring the call result of a subclass of
typewithout a caller.Refs #3429
-
ClassDef.has_dynamic_getattr()now always returns a bool. It returned
Uninferablewhen the__getattr__of a metaclass could not be inferred.Refs #3430
-
modpath_from_file()no longer raisesImportErrorfor a module inside a namespace
package that also exists insite-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()andissubclass()inference constraint when the classinfo is a
PEP 604 union, e.g.isinstance(x, int | str).Refs #3453
-
Apply the
!s,!rand!aconversions 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 reportedinvalid-enum-extension
when such a class was extended, for example on any Django 6models.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 tobool_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
@lazyor@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.NamedTupleis now inferred as atuplesubclass with_asdict,
_replace,_fields,_makeand_field_defaults, as typeshed
declares it.selfin a method of atyping.NamedTuplesubclass finds that
API and the tuple methods such ascountandindexthrough it, so pylint
no longer reportsno-member,unsubscriptable-objector
not-an-iterableonselfthere.Refs #3476
Closes pylint-dev/pylint#7891 -
The
ctypesbrain now gives thevalueargument ofc_int,c_char,
c_doubleand the other simple types the same default as at runtime
(0,0.0,b"\x00","\x00"orFalse).apple = c_int()no
longer makes pylint emitno-value-for-parameteron interpreters where
_ctypesis a built-in module, such as the uv and python-build-standalone
builds.Refs #3482
-
Fix a false positive for
functools.partialobjects stored as class attributes: before Python 3.14, accessing one through an instance does not bindself, and astroid no longer infers a bound method for it.Refs #3491
Closes pylint-dev/pylint#2271
Other Changes
-
A
RecursionErrorraised 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_transformfromastroid.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
towncrierfrom 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 onnodes.Call. The transform visitor previously ran 19
predicates per Call node, each repeating the sameisinstancechecks;
the dispatcher does them once and routes by name via a dict.Refs #1115