You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using DotMap as the baseclass of a custom Config-class.
As a constructor-argument I only want to pass the path to a yaml-file which holds the config values.
This works quite well if I am just using plain dictionaries without nesting:
from dotmap import DotMap
class ConfigNotNested(DotMap):
def __init__(self, filepath='config.yaml'):
# load config-dict from yaml
config_dict = {'a': 1, 'b': 2}
super().__init__(config_dict)
print(ConfigNotNested())
Output:
ConfigNotNested(a=1, b=2)
But now with a nested dictionary this stops working:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-87a4fd97b248> in <module>
11 example = {'a': 1, 'b': {'c': 3, 'd': 4}}
12 super().__init__(example)
---> 13 print(ConfigNested())
<ipython-input-5-87a4fd97b248> in __init__(self)
10 def __init__(self):
11 example = {'a': 1, 'b': {'c': 3, 'd': 4}}
---> 12 super().__init__(example)
13 print(ConfigNested())
venv/lib/python3.7/site-packages/dotmap/__init__.py in __init__(self, *args, **kwargs)
46 else:
47 trackedIDs[idv] = v
---> 48 v = self.__class__(v, _dynamic=self._dynamic, _prevent_method_masking = self._prevent_method_masking, _trackedIDs = trackedIDs)
49 if type(v) is list:
50 l = []
TypeError: __init__() got an unexpected keyword argument '_dynamic'
Expected output:
ConfigNested(a=1, b=DotMap(c=3, d=4))
I think the problem lies in using self.__class__ instead of DotMap, as this will break on subclassing.
Replacing all self.__class__ occurences with DotMap fixes the issue for me.
I can create a pull request if you don't mind or else I can also implement this in a manner you find more appropriate.
The text was updated successfully, but these errors were encountered:
I am using DotMap as the baseclass of a custom Config-class.
As a constructor-argument I only want to pass the path to a yaml-file which holds the config values.
This works quite well if I am just using plain dictionaries without nesting:
Output:
But now with a nested dictionary this stops working:
Output:
Expected output:
I think the problem lies in using
self.__class__
instead ofDotMap
, as this will break on subclassing.Replacing all
self.__class__
occurences withDotMap
fixes the issue for me.I can create a pull request if you don't mind or else I can also implement this in a manner you find more appropriate.
The text was updated successfully, but these errors were encountered: