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

Configuration parsing: "digits + underline" should be considered as a string #862

Open
Jarvis73 opened this issue Feb 23, 2022 · 2 comments

Comments

@Jarvis73
Copy link

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.

Example (main.py):

from sacred import Experiment

ex = Experiment("Exp")

@ex.config
def config():
    name = "abc"

@ex.automain
def main(_config):
    print(_config['name'], type(_config['name']))
  • For python main.py, we get abc <class 'str'>.
  • For python main.py with name=123_456, we get 123456 <class 'int'>, which is quite wired.

A simple solution is to run the script with python main.py with name='"123_456"', but the command is a little messy and not intuitive.

@thequilo
Copy link
Collaborator

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:

  • 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.

@Jarvis73
Copy link
Author

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.

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