[med-svn] [Git][python-team/packages/mypy][upstream] New upstream version 2.4.1
Michael R. Crusoe (@crusoe)
gitlab at salsa.debian.org
Thu Oct 29 14:59:58 GMT 2026
Michael R. Crusoe pushed to branch upstream at Debian Python Team / packages / mypy
Commits:
9ba29196 by Michael R. Crusoe at 2026-10-29T13:47:11+01:00
New upstream version 2.4.1
- - - - -
19 changed files:
- CHANGELOG.md
- PKG-INFO
- mypy-requirements.txt
- mypy.egg-info/PKG-INFO
- mypy.egg-info/requires.txt
- mypy/semanal.py
- mypy/version.py
- mypyc/irbuild/env_class.py
- mypyc/irbuild/function.py
- mypyc/irbuild/generator.py
- mypyc/irbuild/util.py
- mypyc/test-data/run-functions.test
- mypyc/test-data/run-generators.test
- mypyc/test/test_generator_spills.py
- pyproject.toml
- test-data/unit/check-classes.test
- test-data/unit/check-errorcodes.test
- test-data/unit/native-parser.test
- test-requirements.txt
Changes:
=====================================
CHANGELOG.md
=====================================
@@ -259,6 +259,11 @@ Related changes:
Please see [git log](https://github.com/python/typeshed/commits/main?after=6d045a9fff15db83b49b89b14b8dd47ff382470c+0&branch=main&path=stdlib) for the full list of standard library typeshed stub changes.
+### Mypy 2.4.1
+
+- Process overloads as a whole in two-phase type checking (Ivan Levkivskyi, PR [22231](https://github.com/python/mypy/pull/22231))
+- Skip recursive setup for frame-private nested functions in mypyc (Piotr Sawicki, PR [22187](https://github.com/python/mypy/pull/22187))
+
### Acknowledgements
Thanks to all mypy contributors who contributed to this release:
=====================================
PKG-INFO
=====================================
@@ -1,6 +1,6 @@
Metadata-Version: 2.4
Name: mypy
-Version: 2.4.0
+Version: 2.4.1
Summary: Optional static typing for Python
Author-email: Jukka Lehtosalo <jukka.lehtosalo at iki.fi>
License-Expression: MIT
@@ -31,7 +31,7 @@ Requires-Dist: mypy_extensions>=1.0.0
Requires-Dist: pathspec>=1.0.0
Requires-Dist: tomli>=1.1.0; python_version < "3.11"
Requires-Dist: librt>=0.16.0; platform_python_implementation != "PyPy"
-Requires-Dist: ast-serialize<1.0.0,>=0.11.2
+Requires-Dist: ast-serialize<1.0.0,>=0.12.1
Provides-Extra: dmypy
Requires-Dist: psutil>=4.0; extra == "dmypy"
Provides-Extra: mypyc
=====================================
mypy-requirements.txt
=====================================
@@ -6,4 +6,4 @@ mypy_extensions>=1.0.0
pathspec>=1.0.0
tomli>=1.1.0; python_version<'3.11'
librt>=0.16.0; platform_python_implementation != 'PyPy'
-ast-serialize>=0.11.2,<1.0.0
+ast-serialize>=0.12.1,<1.0.0
=====================================
mypy.egg-info/PKG-INFO
=====================================
@@ -1,6 +1,6 @@
Metadata-Version: 2.4
Name: mypy
-Version: 2.4.0
+Version: 2.4.1
Summary: Optional static typing for Python
Author-email: Jukka Lehtosalo <jukka.lehtosalo at iki.fi>
License-Expression: MIT
@@ -31,7 +31,7 @@ Requires-Dist: mypy_extensions>=1.0.0
Requires-Dist: pathspec>=1.0.0
Requires-Dist: tomli>=1.1.0; python_version < "3.11"
Requires-Dist: librt>=0.16.0; platform_python_implementation != "PyPy"
-Requires-Dist: ast-serialize<1.0.0,>=0.11.2
+Requires-Dist: ast-serialize<1.0.0,>=0.12.1
Provides-Extra: dmypy
Requires-Dist: psutil>=4.0; extra == "dmypy"
Provides-Extra: mypyc
=====================================
mypy.egg-info/requires.txt
=====================================
@@ -1,6 +1,6 @@
mypy_extensions>=1.0.0
pathspec>=1.0.0
-ast-serialize<1.0.0,>=0.11.2
+ast-serialize<1.0.0,>=0.12.1
[:platform_python_implementation != "PyPy"]
librt>=0.16.0
=====================================
mypy/semanal.py
=====================================
@@ -4713,7 +4713,7 @@ class SemanticAnalyzer(
and original_def.node.is_inferred
):
for func in self.scope.functions:
- func.def_or_infer_vars = True
+ mark_as_top_level(func)
def analyze_tuple_or_list_lvalue(self, lval: TupleExpr, explicit_type: bool = False) -> None:
"""Analyze an lvalue or assignment target that is a list or tuple."""
@@ -4798,7 +4798,7 @@ class SemanticAnalyzer(
# TODO: should we also set lval.kind = MDEF?
self.type.names[lval.name] = SymbolTableNode(MDEF, v, implicit=True)
for func in self.scope.functions:
- func.def_or_infer_vars = True
+ mark_as_top_level(func)
if self.is_self_member_ref(lval) or self.is_cls_member_ref(lval):
assert self.type, "Self or cls member outside a class"
@@ -4810,7 +4810,7 @@ class SemanticAnalyzer(
and cur_node.node.is_initialized_in_class
):
for func in self.scope.functions:
- func.def_or_infer_vars = True
+ mark_as_top_level(func)
self.check_lvalue_validity(lval.node, lval)
def is_self_member_ref(self, memberexpr: MemberExpr) -> bool:
@@ -8598,6 +8598,18 @@ def erase_func_annotations(func: FuncDef) -> None:
func.unanalyzed_type = None
+def mark_as_top_level(func: FuncBase) -> None:
+ """Mark a function to be processed as part of module top level.
+
+ A non-trivial part here is that we want to keep overloads as a whole.
+ """
+ func.def_or_infer_vars = True
+ if isinstance(func, OverloadedFuncDef):
+ for item in func.items:
+ defn = item if isinstance(item, FuncDef) else item.func
+ defn.def_or_infer_vars = True
+
+
def dotted_identifier_leftmost(s: str) -> str | None:
"""The leftmost component of s, if s is a dotted identifier, else None.
=====================================
mypy/version.py
=====================================
@@ -8,7 +8,7 @@ from mypy import git
# - Release versions have the form "1.2.3".
# - Dev versions have the form "1.2.3+dev" (PLUS sign to conform to PEP 440).
# - Before 1.0 we had the form "0.NNN".
-__version__ = "2.4.0"
+__version__ = "2.4.1"
base_version = __version__
mypy_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
=====================================
mypyc/irbuild/env_class.py
=====================================
@@ -31,6 +31,7 @@ from mypyc.ir.rtypes import RInstance, bitmap_rprimitive, object_rprimitive
from mypyc.irbuild.builder import IRBuilder, SymbolTarget
from mypyc.irbuild.context import FuncInfo, GeneratorClass, ImplicitClass
from mypyc.irbuild.targets import AssignmentTargetAttr
+from mypyc.irbuild.util import get_func_target_symbol
def setup_env_class(builder: IRBuilder) -> ClassIR:
@@ -141,7 +142,7 @@ def load_env_registers(builder: IRBuilder, prefix: str = "") -> None:
# If this is a FuncDef, then make sure to load the FuncDef into its own environment
# class so that the function can be called recursively.
if isinstance(fitem, FuncDef) and fn_info.add_nested_funcs_to_env:
- setup_func_for_recursive_call(builder, fitem, fn_info.callable_class, prefix=prefix)
+ setup_func_for_recursive_call(builder, fitem, fn_info.callable_class)
def load_outer_env(
@@ -298,8 +299,13 @@ def add_vars_to_env(builder: IRBuilder, prefix: str = "") -> None:
)
if fn_info.fitem in builder.encapsulating_funcs:
+ added: set[SymbolNode] = set()
for nested_fn in builder.encapsulating_funcs[fn_info.fitem]:
if isinstance(nested_fn, FuncDef):
+ target_symbol = get_func_target_symbol(nested_fn)
+ if target_symbol in added:
+ continue
+ added.add(target_symbol)
# The return type is 'object' instead of an RInstance of the
# callable class because differently defined functions with
# the same name and signature across conditional blocks
@@ -308,10 +314,10 @@ def add_vars_to_env(builder: IRBuilder, prefix: str = "") -> None:
nested_prefix = prefix
if nested_fn.is_generator or nested_fn.is_coroutine:
nested_prefix = GENERATOR_ATTRIBUTE_PREFIX
- keep_alive = is_free_variable(builder, nested_fn)
- if fn_info.is_generator and not builder.is_captured_by_nested_func(nested_fn):
+ keep_alive = is_free_variable(builder, target_symbol)
+ if fn_info.is_generator and not builder.is_captured_by_nested_func(target_symbol):
builder.add_var_to_generator_frame(
- nested_fn,
+ target_symbol,
object_rprimitive,
fn_info.generator_class.self_reg,
reassign=False,
@@ -319,7 +325,7 @@ def add_vars_to_env(builder: IRBuilder, prefix: str = "") -> None:
)
else:
builder.add_var_to_env_class(
- nested_fn,
+ target_symbol,
object_rprimitive,
env_for_func,
reassign=False,
@@ -328,9 +334,7 @@ def add_vars_to_env(builder: IRBuilder, prefix: str = "") -> None:
)
-def setup_func_for_recursive_call(
- builder: IRBuilder, fdef: FuncDef, base: ImplicitClass, prefix: str = ""
-) -> None:
+def setup_func_for_recursive_call(builder: IRBuilder, fdef: FuncDef, base: ImplicitClass) -> None:
"""Enable calling a nested function (with a callable class) recursively.
Adds the instance of the callable class representing the given
@@ -338,10 +342,18 @@ def setup_func_for_recursive_call(
be called recursively. Note that this needs to be done only for
nested functions.
"""
- # First, set the attribute of the environment class so that GetAttr can be called on it.
prev_env = builder.fn_infos[-2].env_class
- attr_name = prefix + fdef.name
- prev_env.attributes[attr_name] = builder.type_to_rtype(fdef.type)
+ target_symbol = get_func_target_symbol(fdef)
+ target = builder.symtables[-2].get(target_symbol)
+ if (
+ not isinstance(target_symbol, FuncDef)
+ or not isinstance(target, AssignmentTargetAttr)
+ or not isinstance(target.obj.type, RInstance)
+ or target.obj.type.class_ir is not prev_env
+ ):
+ return
+
+ attr_name = target.attr
line = fdef.line
if isinstance(base, GeneratorClass):
@@ -355,7 +367,7 @@ def setup_func_for_recursive_call(
# Obtain the instance of the callable class representing the FuncDef, and add it to the
# current environment.
val = builder.add(GetAttr(prev_env_reg, attr_name, line))
- target = builder.add_local_reg(fdef, object_rprimitive)
+ target = builder.add_local_reg(target_symbol, object_rprimitive)
builder.assign(target, val, line)
=====================================
mypyc/irbuild/function.py
=====================================
@@ -77,6 +77,7 @@ from mypyc.irbuild.env_class import (
)
from mypyc.irbuild.generator import gen_generator_func, gen_generator_func_body
from mypyc.irbuild.targets import AssignmentTarget
+from mypyc.irbuild.util import get_func_target_symbol
from mypyc.primitives.dict_ops import (
dict_get_method_with_none,
dict_new_op,
@@ -925,11 +926,10 @@ def get_func_target(builder: IRBuilder, fdef: FuncDef) -> AssignmentTarget:
If the function was not already defined somewhere, then define it
and add it to the current environment.
"""
- if orig := fdef.original_def:
- if isinstance(orig, Decorator):
- orig = orig.func
+ target_symbol = get_func_target_symbol(fdef)
+ if target_symbol is not fdef:
# Get the target associated with the previously defined FuncDef.
- return builder.lookup(orig)
+ return builder.lookup(target_symbol)
if builder.fn_info.is_generator or builder.fn_info.add_nested_funcs_to_env:
return builder.lookup(fdef)
=====================================
mypyc/irbuild/generator.py
=====================================
@@ -111,9 +111,7 @@ def gen_generator_func_body(builder: IRBuilder, fn_info: FuncInfo, func_reg: Val
and top_level
and top_level.add_nested_funcs_to_env
):
- setup_func_for_recursive_call(
- builder, fitem, builder.fn_info.generator_class, prefix=GENERATOR_ATTRIBUTE_PREFIX
- )
+ setup_func_for_recursive_call(builder, fitem, builder.fn_info.generator_class)
cleanup_on_error = BasicBlock()
builder.builder.push_error_handler(cleanup_on_error)
create_switch_for_generator_class(builder)
=====================================
mypyc/irbuild/util.py
=====================================
@@ -346,6 +346,14 @@ def get_func_def(op: FuncDef | Decorator | OverloadedFuncDef) -> FuncDef:
return op
+def get_func_target_symbol(fdef: FuncDef) -> FuncDef | Var:
+ """Return the symbol used to store a possibly redefined function."""
+ original = fdef.original_def
+ if isinstance(original, Decorator):
+ return original.func
+ return original or fdef
+
+
def concrete_arg_kind(kind: ArgKind) -> ArgKind:
"""Find the concrete version of an arg kind that is being passed."""
if kind == ARG_OPT:
=====================================
mypyc/test-data/run-functions.test
=====================================
@@ -1399,6 +1399,33 @@ print(f(1))
[out]
2
+[case testReassignedNestedFunction]
+from typing import Callable, Generator
+
+def outer(flag: bool) -> list[int]:
+ out: list[int] = []
+ f: Callable[[int], None] = lambda n: out.append(-1)
+
+ def swap() -> None:
+ nonlocal f
+ f = lambda n: out.append(100 + n)
+
+ if flag:
+ def f(n: int) -> None:
+ def k(m: int) -> int:
+ return k(m - 1) if m else 0
+
+ out.append(n + k(2))
+ if n == 0:
+ swap()
+ f(1) # should call the lambda installed by swap()
+ f(0)
+ return out
+
+def test_reassigned_nested_function() -> None:
+ assert outer(False) == [-1]
+ assert outer(True) == [0, 101]
+
[case testStarArgFastPaths]
from typing import Any, Mapping
def fn(x: str, y: int) -> str:
=====================================
mypyc/test-data/run-generators.test
=====================================
@@ -825,6 +825,38 @@ def test_nested_generator_private_spill() -> None:
assert yields == ("right",)
assert value == "capturedleftsent"
+[case testNestedGeneratorPrivateHelper]
+from typing import Iterator
+
+def outer() -> Iterator[int]:
+ def captured() -> Iterator[int]:
+ yield 1
+
+ def private() -> Iterator[int]:
+ yield from captured()
+
+ yield from private()
+
+def test_nested_generator_private_helper() -> None:
+ assert list(outer()) == [1]
+
+[case testRedefinedNestedGeneratorHelper]
+from typing import Iterator
+
+def redefined_nested_helper(flag: bool) -> Iterator[int]:
+ if flag:
+ def helper(n: int) -> int:
+ return 1
+ else:
+ def helper(n: int) -> int:
+ return helper(1) if not n else 2
+
+ yield helper(0)
+
+def test_redefined_nested_generator_helper() -> None:
+ assert list(redefined_nested_helper(True)) == [1]
+ assert list(redefined_nested_helper(False)) == [2]
+
[case testGeneratorPrivateAndEscapedBindings]
from typing import Any, Callable, Generator, Iterator
=====================================
mypyc/test/test_generator_spills.py
=====================================
@@ -184,6 +184,56 @@ def gen() -> Iterator[Any]:
)
assert environment is not frame
+ def test_nested_generator_private_helper_stays_on_frame(self) -> None:
+ module, _, _, _ = build_ir_for_single_file2("""\
+from typing import Iterator
+
+def outer() -> Iterator[int]:
+ def captured() -> Iterator[int]:
+ yield 1
+ def private() -> Iterator[int]:
+ yield from captured()
+ yield from private()
+""".splitlines())
+ outer_frame = next(cl for cl in module.classes if cl.name == "outer_gen")
+ environment_type = outer_frame.attributes[ENV_ATTR_NAME]
+ assert isinstance(environment_type, RInstance)
+ environment = environment_type.class_ir
+
+ assert GENERATOR_ATTRIBUTE_PREFIX + "captured" in environment.attributes
+ assert "private" in frame_variables(outer_frame)
+ assert GENERATOR_ATTRIBUTE_PREFIX + "private" not in environment.attributes
+
+ private_frame = next(cl for cl in module.classes if cl.name.startswith("private_gen___"))
+ private_helper = private_frame.env_user_function
+ assert private_helper is not None
+ assert not any(
+ isinstance(op, GetAttr) and op.attr == GENERATOR_ATTRIBUTE_PREFIX + "private"
+ for block in private_helper.blocks
+ for op in block.ops
+ )
+
+ def test_redefined_nested_helper_has_single_storage_location(self) -> None:
+ module, _, _, _ = build_ir_for_single_file2("""\
+from typing import Iterator
+
+def outer(flag: bool) -> Iterator[int]:
+ if flag:
+ def helper(n: int) -> int:
+ return 1
+ else:
+ def helper(n: int) -> int:
+ return helper(1) if not n else 2
+ yield helper(0)
+""".splitlines())
+ outer_frame = next(cl for cl in module.classes if cl.name == "outer_gen")
+ environment_type = outer_frame.attributes[ENV_ATTR_NAME]
+ assert isinstance(environment_type, RInstance)
+ environment = environment_type.class_ir
+
+ assert GENERATOR_ATTRIBUTE_PREFIX + "helper" in environment.attributes
+ assert "helper" not in frame_variables(outer_frame)
+
def test_nested_finally_promotes_each_saved_exception(self) -> None:
cl = generator_class(
"""\
=====================================
pyproject.toml
=====================================
@@ -15,7 +15,7 @@ requires = [
"types-psutil",
"types-setuptools",
# required to work around a mypyc import bug
- "ast-serialize>=0.11.2,<1.0.0",
+ "ast-serialize>=0.12.1,<1.0.0",
]
build-backend = "setuptools.build_meta"
@@ -59,7 +59,7 @@ dependencies = [
"pathspec>=1.0.0",
"tomli>=1.1.0; python_version<'3.11'",
"librt>=0.16.0; platform_python_implementation != 'PyPy'",
- "ast-serialize>=0.11.2,<1.0.0",
+ "ast-serialize>=0.12.1,<1.0.0",
]
dynamic = ["version"]
=====================================
test-data/unit/check-classes.test
=====================================
@@ -9741,3 +9741,16 @@ class C:
reveal_type(C.x) # N: Revealed type is "builtins.int | None"
[builtins fixtures/classmethod.pyi]
+
+[case testSettablePropertyGetterCheckedWhenPartOfInterface]
+class A:
+ @property
+ def p(self) -> str:
+ def nested() -> int:
+ return "no" # E: Incompatible return value type (got "str", expected "int")
+ return 0 # E: Incompatible return value type (got "int", expected "str")
+
+ @p.setter
+ def p(self, value: int) -> None:
+ self.x = value
+[builtins fixtures/property.pyi]
=====================================
test-data/unit/check-errorcodes.test
=====================================
@@ -848,7 +848,7 @@ main:1: error: Name "y" is not defined [name-defined]
main:2: error: Name "ignored" is not defined [name-defined]
main:2: error: Name "y" is not defined [name-defined]
-[case testErrorCodeTypeIgnoreMisspelled2]
+[case testErrorCodeTypeIgnoreMisspelled2-skip]
x = y # type: int # type: ignored[foo]
x = y # type: int # type: ignored [foo]
[out]
=====================================
test-data/unit/native-parser.test
=====================================
@@ -3116,3 +3116,13 @@ MypyFile:1(
Args(
NameExpr(x)
StrExpr())))))))
+
+[case testNoneInStringType]
+x: "None"
+[out]
+MypyFile:1(
+ AssignmentStmt:1(
+ NameExpr(x)
+ TempNode:1(
+ Any)
+ None?))
=====================================
test-requirements.txt
=====================================
@@ -4,7 +4,7 @@
#
# pip-compile --allow-unsafe --output-file=test-requirements.txt --strip-extras test-requirements.in
#
-ast-serialize==0.11.2
+ast-serialize==0.12.1
# via -r mypy-requirements.txt
attrs==26.1.0
# via -r test-requirements.in
View it on GitLab: https://salsa.debian.org/python-team/packages/mypy/-/commit/9ba2919608c8b29584fdb597ecc12fd3c0111b57
--
View it on GitLab: https://salsa.debian.org/python-team/packages/mypy/-/commit/9ba2919608c8b29584fdb597ecc12fd3c0111b57
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20261029/9c20bd38/attachment-0001.htm>
More information about the debian-med-commit
mailing list