Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump() will fail if some key is an integer #54

Open
Zeltserj opened this issue Apr 13, 2022 · 1 comment
Open

dump() will fail if some key is an integer #54

Zeltserj opened this issue Apr 13, 2022 · 1 comment

Comments

@Zeltserj
Copy link

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
Copy link

luowyang commented Apr 13, 2022

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.

Zeltserj added a commit to Zeltserj/yacs that referenced this issue Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants