diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2020-05-17 18:53:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 18:53:01 -0700 |
commit | 9681953c99b686cf23d1c476a2b26d2ddbec7694 (patch) | |
tree | 599a06df91b58d1d3967546c7604c74ebba16b62 | |
parent | eefd4e033334a2a1d3929d0f7978469e5b5c4e56 (diff) | |
download | cpython-git-9681953c99b686cf23d1c476a2b26d2ddbec7694.tar.gz |
bpo-39058: Preserve attribute order in argparse Namespace reprs. (GH-17621)
-rw-r--r-- | Lib/argparse.py | 2 | ||||
-rw-r--r-- | Lib/test/test_argparse.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-12-15-19-17-10.bpo-39058.7ci-vd.rst | 4 |
3 files changed, 6 insertions, 2 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index 9c710cef5b..2677ef63e9 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -129,7 +129,7 @@ class _AttributeHolder(object): return '%s(%s)' % (type_name, ', '.join(arg_strings)) def _get_kwargs(self): - return sorted(self.__dict__.items()) + return list(self.__dict__.items()) def _get_args(self): return [] diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 9899a53d6d..e82a0c39c2 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -4725,7 +4725,7 @@ class TestStrings(TestCase): def test_namespace(self): ns = argparse.Namespace(foo=42, bar='spam') - string = "Namespace(bar='spam', foo=42)" + string = "Namespace(foo=42, bar='spam')" self.assertStringEqual(ns, string) def test_namespace_starkwargs_notidentifier(self): diff --git a/Misc/NEWS.d/next/Library/2019-12-15-19-17-10.bpo-39058.7ci-vd.rst b/Misc/NEWS.d/next/Library/2019-12-15-19-17-10.bpo-39058.7ci-vd.rst new file mode 100644 index 0000000000..fff13223bc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-12-15-19-17-10.bpo-39058.7ci-vd.rst @@ -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. |