yacs icon indicating copy to clipboard operation
yacs copied to clipboard

Evaluation of strings

Open Rizhiy opened this issue 5 years ago • 4 comments

https://github.com/rbgirshick/yacs/blob/aabe5bd54d193996ceedcff650cff10c38b1f90b/yacs/config.py#L410

This part makes yacs inconsistent with yaml. In yaml if you want a number to be interpreted as a string you can put it in quotes (e.g. 10 vs "10"), but in yacs they will be both converted to numbers.

In which cases is eval used and would it be possible to add an option to disable it?

Rizhiy avatar Jul 23 '19 08:07 Rizhiy

Hi. I also have the same issue. I am trying to add a phone number but its throwing Type mismatch error.

sender: "+13342924471"    # sender mobile number. 

@InnovArul and @Rizhiy, do you guys know any work around until the PR is merged?

muzammil360 avatar Jan 01 '20 17:01 muzammil360

No fix yet, please note that #35 will introduce problems with +, so I don't advise using it.

Rizhiy avatar Jan 01 '20 19:01 Rizhiy

I see. Thanks for the examples. I didn't think of this scenario. In my case, I just needed to mention the integer as string in YACS config. Not with a "+".

For your scenario, one simple workaround I see is to mention the phone numbers within a tuple. i.e., sender: ("+13342924471",)

Meanwhile, I have pushed the fix for your scenario (into https://github.com/rbgirshick/yacs/pull/35) that @Rizhiy was suggesting. It seems good so far/passes all tests in yacs/tests.py. I hope it doesn't affect any other functionalities.

InnovArul avatar Jan 01 '20 22:01 InnovArul

@InnovArul thanks for the tuple hack suggestion. Though I have used another hack for the time being:

phone_str = "+{}".format(cfg["phone_num"])

This way I force + before the string. But I guess the approach can be quite buggy in case someone messes with the config file.

muzammil360 avatar Jan 02 '20 17:01 muzammil360