omni-us / jsonargparse

Implement minimal boilerplate CLIs derived from type hints and parse from command line, config files and environment variables
https://jsonargparse.readthedocs.io
MIT License
328 stars 49 forks source link

Passing paths to python variables #439

Open EthanMarx opened 10 months ago

EthanMarx commented 10 months ago

🚀 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

mauvilsa commented 10 months ago

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.