Skip to content

Commit

Permalink
Do not include config_class in loaded config object
Browse files Browse the repository at this point in the history
  • Loading branch information
mdw771 committed May 26, 2024
1 parent dfee9cb commit e6f33bc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion generic_trainer/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

@dataclasses.dataclass
class OptionContainer:

class SkipKey:
pass

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.globals = {}
Expand Down Expand Up @@ -48,7 +52,9 @@ def get_serializable_dict(self):

def deserizalize_dict(self, d):
for key in d.keys():
self.__dict__[key] = self.string_to_object(key, d[key])
v = self.string_to_object(key, d[key])
if not isinstance(v, self.SkipKey):
self.__dict__[key] = v

def dump_to_json(self, filename):
try:
Expand Down Expand Up @@ -98,6 +104,8 @@ def string_to_object(self, key, value):
"globals() to load_from_json:\n"
" configs.load_from_json(filename, namespace=globals())\n".format(key, e)
)
elif key == 'config_class':
return self.SkipKey()
elif isinstance(value, (list, tuple)):
value = [self.string_to_object(key, v) for v in value]
elif isinstance(value, str) and (res := re.match(r"<class '(.+)'>", value)):
Expand Down

0 comments on commit e6f33bc

Please sign in to comment.