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
{{ message }}
Repository navigation
Configuration parsing: "digits + underline" should be considered as a string #862
When parsing configurations (such as name=123_456), maybe the digits + underline should be considered as a string? Now the underline will be ignored and the remaining digits are treated as an integer.
Sacred treats the arguments of configuration values as python literals (and treats everything it can't handle as a string), and what you see is actually just the way that python interprets numbers. I actually like the idea to just treat everything as python literal because it seems intuitive (to me, at least). But, I agree that we can come up with weird things:
For python main.py with name=0xdeef, we get 57071 <class 'int'>
For python main.py with name=1j, we get a TypeError (because JSON apparently can't serialize complex numbers?)
For python main.py with name=1e-1, we get 0.1 <class 'float'>. Obvious, but I really wouldn't expect that when seeing name=1e-1
python main.py with name=['a'] we get [a] <class 'str'>, and
For python main.py with name=["'a'"], we get ['a'] <class 'sacred.config.custom_containers.ReadOnlyList'>
This list could probably go on for a while, and after writing it down, I start to feel that it is actually not that intuitive. But, this list also shows that if we start to have exceptions to the "treat it as a literal" rule, we'll end up with many of them.
Thanks for the detailed explanation. Now I can understand the design purpose, and maybe it is more reasonable, in spite that we have to use '"xxx"' in some cases.
Activity
thequilo commentedon Feb 23, 2022
Hi @Jarvis73!
Sacred treats the arguments of configuration values as python literals (and treats everything it can't handle as a string), and what you see is actually just the way that python interprets numbers. I actually like the idea to just treat everything as python literal because it seems intuitive (to me, at least). But, I agree that we can come up with weird things:
python main.py with name=0xdeef, we get57071 <class 'int'>python main.py with name=1j, we get aTypeError(because JSON apparently can't serialize complex numbers?)python main.py with name=1e-1, we get0.1 <class 'float'>. Obvious, but I really wouldn't expect that when seeingname=1e-1python main.py with name=['a']we get[a] <class 'str'>, andpython main.py with name=["'a'"], we get['a'] <class 'sacred.config.custom_containers.ReadOnlyList'>This list could probably go on for a while, and after writing it down, I start to feel that it is actually not that intuitive. But, this list also shows that if we start to have exceptions to the "treat it as a literal" rule, we'll end up with many of them.
Jarvis73 commentedon Feb 24, 2022
Hi @thequilo!
Thanks for the detailed explanation. Now I can understand the design purpose, and maybe it is more reasonable, in spite that we have to use
'"xxx"'in some cases.