mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-39058: Preserve attribute order in argparse Namespace reprs. (GH-17621)
This commit is contained in:
parent
eefd4e0333
commit
9681953c99
3 changed files with 6 additions and 2 deletions
|
@ -129,7 +129,7 @@ class _AttributeHolder(object):
|
||||||
return '%s(%s)' % (type_name, ', '.join(arg_strings))
|
return '%s(%s)' % (type_name, ', '.join(arg_strings))
|
||||||
|
|
||||||
def _get_kwargs(self):
|
def _get_kwargs(self):
|
||||||
return sorted(self.__dict__.items())
|
return list(self.__dict__.items())
|
||||||
|
|
||||||
def _get_args(self):
|
def _get_args(self):
|
||||||
return []
|
return []
|
||||||
|
|
|
@ -4725,7 +4725,7 @@ class TestStrings(TestCase):
|
||||||
|
|
||||||
def test_namespace(self):
|
def test_namespace(self):
|
||||||
ns = argparse.Namespace(foo=42, bar='spam')
|
ns = argparse.Namespace(foo=42, bar='spam')
|
||||||
string = "Namespace(bar='spam', foo=42)"
|
string = "Namespace(foo=42, bar='spam')"
|
||||||
self.assertStringEqual(ns, string)
|
self.assertStringEqual(ns, string)
|
||||||
|
|
||||||
def test_namespace_starkwargs_notidentifier(self):
|
def test_namespace_starkwargs_notidentifier(self):
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
In the argparse module, the repr for Namespace() and other argument holders
|
||||||
|
now displayed in the order attributes were added. Formerly, it displayed in
|
||||||
|
alphabetical order even though argument order is preserved the user visible
|
||||||
|
parts of the module.
|
Loading…
Add table
Add a link
Reference in a new issue