From 2e058d681c1f5db8c57d7be3708993352f91166e Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Sun, 2 Jul 2023 09:50:48 +0200 Subject: [PATCH] Fix hard-coded class reference in fromkeys() 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 --- immutabledict/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/immutabledict/__init__.py b/immutabledict/__init__.py index cd9dace..951b4ce 100644 --- a/immutabledict/__init__.py +++ b/immutabledict/__init__.py @@ -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)