This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gousaiyang
Recipients gousaiyang, rhettinger
Date 2020-04-13.05:39:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1586756377.52.0.208393303298.issue40265@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2020-04-13 05:39:37gousaiyangsetrecipients: + gousaiyang, rhettinger
2020-04-13 05:39:37gousaiyangsetmessageid: <1586756377.52.0.208393303298.issue40265@roundup.psfhosted.org>
2020-04-13 05:39:37gousaiyanglinkissue40265 messages
2020-04-13 05:39:37gousaiyangcreate