Closed scottstanie closed 4 weeks ago
Since this is only an issue because argparse
uses the %
-style formatting, I have a one line fix here. I'm not sure if there are other opinions about more general fixes though.
In [5]: %run pydantic-settings-bug.py --date-fmt1
usage: pydantic-settings.bug.py [-h] [--date_fmt1 str]
options:
-h, --help show this help message and exit
--date_fmt1 str (default: %Y%m%d)
Thanks @scottstanie for reporting this.
@kschwab could you please take a look?
Thanks @scottstanie for the find and proposed fix 👍🏾
I would make one small change to keep it specific to argparse, that way we avoid any potential issues with other external parsers that do not need the replacement:
return _help.replace('%', '%%') if issubclass(type(self._root_parser), ArgumentParser) else _help
the fix has been released in new pydantic-settings 2.3.2
The new CLI parsing is awesome, but I've stumbled across an annoying issue relating to
argparse
:Stripping down the demo to one string field, the default can't have a
%
in it orargparse
errors withValueError: unsupported format character...
Full traceback:
Versions: