bpo-39957: Change Signature.parameters to OrderedDict (GH-18988)

This commit is contained in:
Jens Reidel 2020-03-18 03:22:46 +01:00 committed by GitHub
parent 29356e03d4
commit 611836a69a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -2733,7 +2733,7 @@ class Signature:
A Signature object has the following public attributes and methods:
* parameters : dict
* parameters : OrderedDict
An ordered mapping of parameters' names to the corresponding
Parameter objects (keyword-only arguments are in the same order
as listed in `code.co_varnames`).
@ -2763,10 +2763,10 @@ class Signature:
"""
if parameters is None:
params = {}
params = OrderedDict()
else:
if __validate_parameters__:
params = {}
params = OrderedDict()
top_kind = _POSITIONAL_ONLY
kind_defaults = False
@ -2805,7 +2805,7 @@ class Signature:
params[name] = param
else:
params = {param.name: param for param in parameters}
params = OrderedDict((param.name, param) for param in parameters)
self._parameters = types.MappingProxyType(params)
self._return_annotation = return_annotation

View File

@ -2077,7 +2077,7 @@ class TestSignatureObject(unittest.TestCase):
P = inspect.Parameter
self.assertEqual(str(S()), '()')
self.assertEqual(repr(S().parameters), 'mappingproxy({})')
self.assertEqual(repr(S().parameters), 'mappingproxy(OrderedDict())')
def test(po, pk, pod=42, pkd=100, *args, ko, **kwargs):
pass
@ -3181,6 +3181,11 @@ class TestSignatureObject(unittest.TestCase):
l = list(signature.parameters)
self.assertEqual(l, unsorted_keyword_only_parameters)
def test_signater_parameters_is_ordered(self):
p1 = inspect.signature(lambda x, y: None).parameters
p2 = inspect.signature(lambda y, x: None).parameters
self.assertNotEqual(p1, p2)
class TestParameterObject(unittest.TestCase):
def test_signature_parameter_kinds(self):