Skip to content

Commit bdf02ce

Browse files
re-add kwargs to __new__ (#273)
1 parent 7918f3b commit bdf02ce

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

immutabledict/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def fromkeys(
3939
) -> immutabledict[_K, _V]:
4040
return cls(cls.dict_cls.fromkeys(seq, value))
4141

42-
def __new__(cls, *args: Any) -> immutabledict[_K, _V]:
42+
def __new__(cls, *args: Any, **kwargs: Any) -> immutabledict[_K, _V]:
4343
inst = super().__new__(cls)
44-
setattr(inst, "_dict", cls.dict_cls(*args))
44+
setattr(inst, "_dict", cls.dict_cls(*args, **kwargs))
4545
setattr(inst, "_hash", None)
4646
return inst
4747

tests/test_immutabledict.py

+4
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ def test_performance(self, statement: str) -> None:
215215

216216
assert time_immutable < 1.2 * time_standard
217217

218+
def test_new_kwargs(self) -> None:
219+
immutable_dict: immutabledict[str, int] = immutabledict(a=1, b=2)
220+
assert immutable_dict == {"a": 1, "b": 2} == dict(a=1, b=2)
221+
218222

219223
class TestImmutableOrderedDict:
220224
def test_ordered(self) -> None:

0 commit comments

Comments
 (0)