Skip to content

Commit

Permalink
Fix hard-coded class reference in fromkeys()
Browse files Browse the repository at this point in the history
If you use ImmutableOrderedDict.fromkeys() or any other custo subclass that overrides the `dict_cls`, it will construct a regular dict and not an ordered dict since the `fromkeys()` function hardcodes `dict` instead of the class's `dict_cls`. This PR fixes that
  • Loading branch information
cthoyt committed Jul 2, 2023
1 parent 6d8b83e commit 2e058d6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion immutabledict/__init__.py
Expand Up @@ -23,7 +23,7 @@ class immutabledict(Mapping[_K, _V]):
def fromkeys(
cls, seq: Iterable[_K], value: Optional[_V] = None
) -> "immutabledict[_K, _V]":
return cls(dict.fromkeys(seq, value))
return cls(cls.dict_cls.fromkeys(seq, value))

def __init__(self, *args: Any, **kwargs: Any) -> None:
self._dict = self.dict_cls(*args, **kwargs)
Expand Down

0 comments on commit 2e058d6

Please sign in to comment.