Closed lmmx closed 2 years ago
This is because dataclasses default to autogenerating a docstring which is the signature of the constructor, and which as a consequence is not valid rst (as it contains the asterisk to mark kwonly args). You can override that invalid docstring by putting in your own.
When using the new Python 3.10
KW_ONLY
sentinel value in a dataclass, wrapping it withdefopt.run
, the CLI gives a warning (originating from docutils):A small reproducible example can be found in this commit:
The code can be reduced to
and the module
new_home.py
I tried to filter it with the warnings module but it didn't work, which I think means it didn't come from there.
There are 57 hits for this in the docutils package, I'm not sure where exactly it's coming from
Without this I don't have as much control over the creation of CLIs from dataclasses, which is a shame as it'd be very convenient.
More info on the feature at StackOverflow and the official Python docs
Update: I was trying to use this to control the generation of positional vs. optional CLI flags, but I've now discovered I can do this by passing
cli_options="has_default"
todefopt.run
so this is more of a courtesy note, and please feel free to close if not useful. I suspect the source is when the help message is generated, and the*
for the keyword only signature is interpreted as the italics start symbol