Message359118
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 |
|
Date |
User |
Action |
Args |
2019-12-31 15:23:53 | shihai1991 | set | recipients:
+ shihai1991 |
2019-12-31 15:23:53 | shihai1991 | set | messageid: <1577805833.81.0.166775558073.issue39173@roundup.psfhosted.org> |
2019-12-31 15:23:53 | shihai1991 | link | issue39173 messages |
2019-12-31 15:23:53 | shihai1991 | create | |
|