New submission from hai shi <shihai1...@126.com>: 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()) else: return self.__dict__.items() ``` some other bpos have discussed this topic too: issue39075、issue39058 ---------- components: Library (Lib) messages: 359118 nosy: shihai1991 priority: normal severity: normal status: open title: _AttributeHolder of argparse should support the sort function or not? type: enhancement _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39173> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com