Skip to content

Commit

Permalink
fix: add DictDefault set_item
Browse files Browse the repository at this point in the history
  • Loading branch information
NanoCode012 committed Feb 17, 2025
1 parent cab2c11 commit 65a83b7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/axolotl/utils/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,26 @@ def __missing__(self, key):

def __or__(self, other):
return DictDefault(super().__ror__(other))

def __setitem__(self, name, value):
# workaround for pickle/unpickle issues and __frozen not being available
try:
isFrozen = hasattr( # pylint: disable=invalid-name
self, "__frozen"
) and object.__getattribute__(self, "__frozen")
except AttributeError:
isFrozen = False # pylint: disable=invalid-name

if isFrozen and name not in super().keys():
raise KeyError(name)
super(Dict, self).__setitem__(name, value) # pylint: disable=bad-super-call
try:
p = object.__getattribute__(self, "__parent")
key = object.__getattribute__(self, "__key")
except AttributeError:
p = None
key = None
if p is not None:
p[key] = self
object.__delattr__(self, "__parent")
object.__delattr__(self, "__key")

0 comments on commit 65a83b7

Please sign in to comment.