Saiyang Gou <[email protected]> added the comment:
> The primary function of the Namespace class is to hold valid attributes and
> to allow the dot operator to access those attributes.
I acknowledge this. Invalid attribute names are not useful in production.
However, some crazy people like me would define arguments like these, producing
an repr string that does not round-trip:
>>> from argparse import ArgumentParser
>>> parser = ArgumentParser()
>>> parser.add_argument('-8')
>>> parser.add_argument('-@')
>>> parser.add_argument('--return')
>>> parser.parse_args(['-8', 'y', '-@', 'a.com', '--return', 'foo'])
Namespace(return='foo', **{'8': 'y', '@': 'a.com'})
(I know I can use the `dest` argument to define an alternative name to store in
the namespace.)
The reason why I open this issue is that I see issue 24360 already tried to
improve the repr string for invalid names by using the `isidentifier` check.
(Which is almost "as unuseful as this issue" for production use, since repr is
almost only used for development instead of production.) The original author
thought the improvement was enough to be round-trippable but missed the special
case of keywords, and my patch will fix this.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40265>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com