diff --git a/src/frozendict/core.py b/src/frozendict/core.py index d59df6b..1a191a4 100644 --- a/src/frozendict/core.py +++ b/src/frozendict/core.py @@ -7,6 +7,8 @@ def immutable(self, *args, **kwargs): raise AttributeError(f"'{self.__class__.__name__}' object is read-only") +_empty_frozendict = None + class frozendict(dict): r""" A simple immutable dictionary. @@ -50,11 +52,13 @@ def __new__(e4b37cdf_d78a_4632_bade_6f0579d8efac, *args, **kwargs): # empty singleton - start if self.__class__ == frozendict and not len(self): - try: - self = cls.empty + global _empty_frozendict + + if _empty_frozendict is None: + _empty_frozendict = self + else: + self = _empty_frozendict continue_creation = False - except AttributeError: - cls.empty = self # empty singleton - end