omegaconf icon indicating copy to clipboard operation
omegaconf copied to clipboard

How to properly escape ???

Open trias702 opened this issue 2 years ago • 2 comments
trafficstars

I'm creating a ListConfig out of a python list of strings, and one element of my python list is '???', a python string with 3 question marks.

Unfortunately, if I include such a string into ListConfig, and later that ListConfig is part of a resolve call (for example OmegaConf.to_object()), then OmegaConf throws an error for Missing Value, because ??? is a special, reserved phrase.

How can I properly escape ??? so this doesn't happen?

trias702 avatar Jan 31 '23 22:01 trias702

Here's a workaround using resolvers:

>>> OmegaConf.register_new_resolver("three_question_marks", lambda: "???")
>>> cfg = OmegaConf.create("a: ${three_question_marks:}");
>>> OmegaConf.to_object(cfg)
{'a': '???'}

Jasha10 avatar Feb 06 '23 09:02 Jasha10

That worked great, thank you kindly!

On Mon, 6 Feb 2023, 01:45 Jasha Sommer-Simpson, @.***> wrote:

Here's a hack using resolvers to get the job done:

OmegaConf.register_new_resolver("three_question_marks", lambda: "???")>>> cfg = OmegaConf.create("a: ${three_question_marks:}");>>> OmegaConf.to_object(cfg) {'a': '???'}

— Reply to this email directly, view it on GitHub https://github.com/omry/omegaconf/issues/1056#issuecomment-1418795700, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGFLGNGW2RXPWLUJSRIHCUDWWDB4DANCNFSM6AAAAAAUM7CNKM . You are receiving this because you authored the thread.Message ID: @.***>

trias702 avatar Feb 07 '23 01:02 trias702