Previous custom dict_type yields an error on python 3.6 and up
Yarboa opened this issue · 1 comments
Yarboa commented
class M(dict):
def __setitem__(self, key, value):
if len(value) > 1:
return
if key in self:
items = self[key]
new = value[0] if type(value) is list else value
if new not in items:
items.append(new)
else:
super().__setitem__(key, value)
config_parser_args
{'allow_no_value': True, 'strict': False, 'dict_type': <class 'main.main..M'>}
get_value = ConfigParser(**config_parser_args)
Raising the following Error:
AttributeError: 'ConfigParser' object has no attribute 'default_section'
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
/home/yrachman/os-client/tmp/python-test/venv-3.6/lib/python3.6/site-packages/backports/configparser/init.py(1383)_options()
-> if self._name != self._parser.default_section:
python -V Python 3.6.8
configparser 5.0.0
Removing dict_type, works well
Had the following code working till python3.5 w/ configparser 4.0.2
Yarboa commented
Closing this,
Override of OrderedDict solved it
class M(OrderedDict):
def __setitem__(self, key, value):
print("key", key, " value:" ,value, end=" ")
v_val = self.get(key)
if v_val is not None and type(value)==list:
v_val.append(value[0])
else:
v_val = value
super().__setitem__(key, v_val)