Skip to content

Commit f76037a

Browse files
Fix frozendict constructor: drop the argument-less __init__ (#15985) (#15989)
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.
1 parent eda55c0 commit f76037a

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from typing import Any
5+
from typing_extensions import assert_type
6+
7+
if sys.version_info >= (3, 15):
8+
# Regression test for gh-15985: ``frozendict`` can be constructed from
9+
# keyword arguments, a mapping, or an iterable of pairs (not just with no
10+
# arguments).
11+
assert_type(frozendict(), frozendict[Any, Any])
12+
assert_type(frozendict(a=1), frozendict[str, int])
13+
assert_type(frozendict({"x": 1}), frozendict[str, int])
14+
assert_type(frozendict([("k", 2)]), frozendict[str, int])
15+
assert_type(frozendict({"x": 1}, y=2), frozendict[str, int])

stdlib/builtins.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,6 @@ if sys.version_info >= (3, 15):
13891389
cls: type[frozendict[str, _VT]], iterable: Iterable[tuple[str, _VT]], /, **kwargs: _VT
13901390
) -> frozendict[str, _VT]: ...
13911391

1392-
def __init__(self) -> None: ...
13931392
def copy(self) -> frozendict[_KT, _VT]: ...
13941393

13951394
@overload

0 commit comments

Comments
 (0)