`dump()` will fail if some key is an integer
Zeltserj opened this issue · 1 comments
Zeltserj commented
Running:
from yacs.config import CfgNode as CN
cfg = CN()
cfg["MYKEY"] = CN()
cfg.MYKEY[1] = "a_sub_value"
print(cfg.dump())
Gives:
Traceback (most recent call last):
File "/Users/zeltserj/yacs/example/main.py", line 5, in <module>
print(cfg.dump())
File "/Users/zeltserj/yacs/yacs/config.py", line 206, in dump
self_as_dict = convert_to_dict(self, [])
File "/Users/zeltserj/yacs/yacs/config.py", line 203, in convert_to_dict
cfg_dict[k] = convert_to_dict(v, key_list + [k])
File "/Users/zeltserj/yacs/yacs/config.py", line 203, in convert_to_dict
cfg_dict[k] = convert_to_dict(v, key_list + [k])
File "/Users/zeltserj/yacs/yacs/config.py", line 196, in convert_to_dict
".".join(key_list), type(cfg_node), _VALID_TYPES
TypeError: sequence item 1: expected str instance, int found
running with "1" instead, works fine.
luowyang commented
It seems that ".".join(key_list) does not accept integer as list element. The same is observed when the config is read from file which contains integer as key. Maybe it should be made clear that pure numbers should not be used as keys, or to parse integer keys as strings.