[issue39058] argparse should preserve argument ordering in Namespace

paul j3 report at bugs.python.org
Tue Dec 17 17:10:31 EST 2019


paul j3 <ajipanca at gmail.com> added the comment:

This patch changes the super class, _AttributeHolder.  ArgumentParser and Actions also inherit from this, though they have their own _get_kwargs methods, and so aren't affected by the sort and its removal.

I just had occasion on stackoverflow to discuss the order in which attributes are added.  A poster wanted to preserve the sys.argv order.

https://stackoverflow.com/questions/58904423/find-the-order-of-arguments-in-argparse-python3/58905067#58905067

Most attributes are added as defaults at the start of parsing - via a loop through parser._actions.  Predefining the namespace, SUPPRESS defaults, parser.set_defaults may alter this default order.

Anyways removing the sort makes sense, and the proposed change phrase "in the order attributes were added" is sufficiently general.

----------
nosy: +paul.j3

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39058>
_______________________________________


More information about the Python-bugs-list mailing list