Skip to content

Commit

Permalink
re-add kwargs to __new__ (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasdiener committed Oct 16, 2023
1 parent 7918f3b commit bdf02ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions immutabledict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def fromkeys(
) -> immutabledict[_K, _V]:
return cls(cls.dict_cls.fromkeys(seq, value))

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

Expand Down
4 changes: 4 additions & 0 deletions tests/test_immutabledict.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ def test_performance(self, statement: str) -> None:

assert time_immutable < 1.2 * time_standard

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


class TestImmutableOrderedDict:
def test_ordered(self) -> None:
Expand Down

0 comments on commit bdf02ce

Please sign in to comment.