Author shihai1991
Recipients shihai1991
Date 2019-12-31.15:23:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Currently, many developers discuss the output of attributes of argparse should be sorted or not?

>>> from argparse import ArgumentParser
>>> parser = ArgumentParser()
>>> _ = parser.add_argument('outstream')
>>> _ = parser.add_argument('instream')
>>> args = parser.parse_args(['out.txt', 'in.txt'])

# Keep the original order
>>> vars(args)

{'outstream': 'out.txt', 'instream': 'in.txt'}
# Order is sorted
>>> args
Namespace(instream='in.txt', outstream='out.txt')

IMHO, the attributes order should be keep the original order by default. If user would like use order the attributes order, we should add a param in `_AttributeHolder` to open sorting or not.

such as:
class _AttributeHolder(object):
    def __init__(self, sort=false):
        self.sort = sort

    def _get_kwargs(self):
        if sort:
            return sorted(self.__dict__.items())
            return self.__dict__.items()

some other bpos have discussed this topic too: issue39075issue39058
Date User Action Args
2019-12-31 15:23:53shihai1991setrecipients: + shihai1991
2019-12-31 15:23:53shihai1991setmessageid: <>
2019-12-31 15:23:53shihai1991linkissue39173 messages
2019-12-31 15:23:53shihai1991create