diff --git a/Lib/argparse.py b/Lib/argparse.py index 5d3ce2ad709f03..e495317cbd4fc8 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -129,7 +129,7 @@ def __repr__(self): 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 60bf19918b79e5..767844d23945e4 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -4687,7 +4687,7 @@ def test_argument(self): 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 00000000000000..fff13223bc4cde --- /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.