yacs icon indicating copy to clipboard operation
yacs copied to clipboard

int -> str is added to allowed casts to overcome int to str incompatibility

Open InnovArul opened this issue 4 years ago • 6 comments

Fix for https://github.com/rbgirshick/yacs/issues/26

InnovArul avatar Dec 28 '19 13:12 InnovArul

Great work @InnovArul. @rbgirshick, any ideas when can this branch be merged and pip package updated?

muzammil360 avatar Jan 01 '20 17:01 muzammil360

I believe this is a wrong fix for my issue as it won't work in all cases, e.g. value "+2" will be converted to "2" in the end, thus losing the +.

The correct fix in my opinion would be to pass target type into _decode_cfg_value and don't use eval if target type is str.

I will try to code it up tomorrow, if I have the time.

Rizhiy avatar Jan 01 '20 19:01 Rizhiy

Thanks for the heads up with this example. I have changed the _decode_cfg_value to handle this. Can you check if this handles your scenario?

InnovArul avatar Jan 02 '20 08:01 InnovArul

@InnovArul @Rizhiy, how about you get configuration type from the default config value and then force that on incoming value!

muzammil360 avatar Jan 02 '20 17:01 muzammil360

@muzammil360 Such validation is already built-in to yacs with the method _check_and_coerce_cfg_value_type (here). But the issue is that, every string is passed through literal_eval (here) which changes +123 to 123. Now, I have changed the code to not to do literal_eval if the data type of the input as well as the expected datatype is a string.

InnovArul avatar Jan 03 '20 06:01 InnovArul

Ah i see. Thanks for the clarification.

On Fri, Jan 3, 2020, 11:28 AM Arulkumar [email protected] wrote:

@muzammil360 https://github.com/muzammil360 Such validation is already built-in to yacs with the method _check_and_coerce_cfg_value_type (here https://github.com/rbgirshick/yacs/blob/7b06e280216451b6f8536538548c75b861d9c22c/yacs/config.py#L460). But the issue is that, every string is passed through literal_eval which changes +123 to 123. Now, I have changed the code to not to do literal_eval if the data type of the input as well as the expected datatype is a string.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rbgirshick/yacs/pull/35?email_source=notifications&email_token=AE3S5IKSCTIWTZTT66KTVYTQ33LKFA5CNFSM4KAMLO5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIAMZNQ#issuecomment-570477750, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE3S5INVK7BYP7MIWXN5FILQ33LKFANCNFSM4KAMLO5A .

muzammil360 avatar Jan 03 '20 11:01 muzammil360