From 1c28261a39de5dab4899795b8d31e6602a309b6d Mon Sep 17 00:00:00 2001 From: Apoorv Darshan Date: Wed, 8 Jul 2026 19:51:45 +0530 Subject: [PATCH 1/2] Fix frozendict constructor: drop the argument-less __init__ frozendict has __new__ overloads for keyword arguments, a mapping and an iterable of pairs, but also declared 'def __init__(self) -> None: ...', so type checkers rejected 'frozendict(a=1)' etc. with 'Expected 0 positional arguments'. Remove the redundant __init__ (like other __new__-constructed builtins) so the __new__ overloads govern construction. Added a test case. --- .../test_cases/builtins/check_frozendict-py315.py | 12 ++++++++++++ stdlib/builtins.pyi | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 stdlib/@tests/test_cases/builtins/check_frozendict-py315.py diff --git a/stdlib/@tests/test_cases/builtins/check_frozendict-py315.py b/stdlib/@tests/test_cases/builtins/check_frozendict-py315.py new file mode 100644 index 000000000000..a970cf402dc4 --- /dev/null +++ b/stdlib/@tests/test_cases/builtins/check_frozendict-py315.py @@ -0,0 +1,12 @@ +from __future__ import annotations + +from typing import Any +from typing_extensions import assert_type + +# Regression test for gh-15985: ``frozendict`` can be constructed from keyword +# arguments, a mapping, or an iterable of pairs (not just with no arguments). +assert_type(frozendict(), frozendict[Any, Any]) +assert_type(frozendict(a=1), frozendict[str, int]) +assert_type(frozendict({"x": 1}), frozendict[str, int]) +assert_type(frozendict([("k", 2)]), frozendict[str, int]) +assert_type(frozendict({"x": 1}, y=2), frozendict[str, int]) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index fdd554c7fcd7..096d440ac38c 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1389,7 +1389,6 @@ if sys.version_info >= (3, 15): cls: type[frozendict[str, _VT]], iterable: Iterable[tuple[str, _VT]], /, **kwargs: _VT ) -> frozendict[str, _VT]: ... - def __init__(self) -> None: ... def copy(self) -> frozendict[_KT, _VT]: ... @overload From be32842203c848b062ae5a1b4072543b9588432b Mon Sep 17 00:00:00 2001 From: Apoorv Darshan Date: Wed, 8 Jul 2026 22:17:56 +0530 Subject: [PATCH 2/2] Guard frozendict test case with sys.version_info >= (3, 15) --- .../builtins/check_frozendict-py315.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/stdlib/@tests/test_cases/builtins/check_frozendict-py315.py b/stdlib/@tests/test_cases/builtins/check_frozendict-py315.py index a970cf402dc4..dd222a4c796f 100644 --- a/stdlib/@tests/test_cases/builtins/check_frozendict-py315.py +++ b/stdlib/@tests/test_cases/builtins/check_frozendict-py315.py @@ -1,12 +1,15 @@ from __future__ import annotations +import sys from typing import Any from typing_extensions import assert_type -# Regression test for gh-15985: ``frozendict`` can be constructed from keyword -# arguments, a mapping, or an iterable of pairs (not just with no arguments). -assert_type(frozendict(), frozendict[Any, Any]) -assert_type(frozendict(a=1), frozendict[str, int]) -assert_type(frozendict({"x": 1}), frozendict[str, int]) -assert_type(frozendict([("k", 2)]), frozendict[str, int]) -assert_type(frozendict({"x": 1}, y=2), frozendict[str, int]) +if sys.version_info >= (3, 15): + # Regression test for gh-15985: ``frozendict`` can be constructed from + # keyword arguments, a mapping, or an iterable of pairs (not just with no + # arguments). + assert_type(frozendict(), frozendict[Any, Any]) + assert_type(frozendict(a=1), frozendict[str, int]) + assert_type(frozendict({"x": 1}), frozendict[str, int]) + assert_type(frozendict([("k", 2)]), frozendict[str, int]) + assert_type(frozendict({"x": 1}, y=2), frozendict[str, int])