jsonargparse icon indicating copy to clipboard operation
jsonargparse copied to clipboard

Passing paths to python variables

Open EthanMarx opened this issue 1 year ago • 2 comments

🚀 Feature request

Given this simple parser setup, is it possible to parse values that are paths to python variables that resolve the the requested type?

parser = jsonargparse.ArgumentParser()
parser.add_argument("--float", type=float)
parser.parse_args(["--float", "math.pi"])

Motivation

Pitch

Alternatives

EthanMarx avatar Jan 26 '24 18:01 EthanMarx

Thank you for the proposal! It is an interesting idea. I need to think about it to see if it could have unexpected consequences. One small comment for now. One thing is that when parsing, an import path resolves to its corresponding value. This might be relatively easy to implement.

A more complex behavior that people could ask for could be that additionally when serializing (dump, save, print_config), the import path is preserved. This would be considerably complex an not be implemented any time soon.

mauvilsa avatar Jan 29 '24 22:01 mauvilsa