bpo-39957: Change Signature.parameters to OrderedDict (GH-18988)
This commit is contained in:
parent
29356e03d4
commit
611836a69a
|
@ -2733,7 +2733,7 @@ class Signature:
|
||||||
|
|
||||||
A Signature object has the following public attributes and methods:
|
A Signature object has the following public attributes and methods:
|
||||||
|
|
||||||
* parameters : dict
|
* parameters : OrderedDict
|
||||||
An ordered mapping of parameters' names to the corresponding
|
An ordered mapping of parameters' names to the corresponding
|
||||||
Parameter objects (keyword-only arguments are in the same order
|
Parameter objects (keyword-only arguments are in the same order
|
||||||
as listed in `code.co_varnames`).
|
as listed in `code.co_varnames`).
|
||||||
|
@ -2763,10 +2763,10 @@ class Signature:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if parameters is None:
|
if parameters is None:
|
||||||
params = {}
|
params = OrderedDict()
|
||||||
else:
|
else:
|
||||||
if __validate_parameters__:
|
if __validate_parameters__:
|
||||||
params = {}
|
params = OrderedDict()
|
||||||
top_kind = _POSITIONAL_ONLY
|
top_kind = _POSITIONAL_ONLY
|
||||||
kind_defaults = False
|
kind_defaults = False
|
||||||
|
|
||||||
|
@ -2805,7 +2805,7 @@ class Signature:
|
||||||
|
|
||||||
params[name] = param
|
params[name] = param
|
||||||
else:
|
else:
|
||||||
params = {param.name: param for param in parameters}
|
params = OrderedDict((param.name, param) for param in parameters)
|
||||||
|
|
||||||
self._parameters = types.MappingProxyType(params)
|
self._parameters = types.MappingProxyType(params)
|
||||||
self._return_annotation = return_annotation
|
self._return_annotation = return_annotation
|
||||||
|
|
|
@ -2077,7 +2077,7 @@ class TestSignatureObject(unittest.TestCase):
|
||||||
P = inspect.Parameter
|
P = inspect.Parameter
|
||||||
|
|
||||||
self.assertEqual(str(S()), '()')
|
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):
|
def test(po, pk, pod=42, pkd=100, *args, ko, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
@ -3181,6 +3181,11 @@ class TestSignatureObject(unittest.TestCase):
|
||||||
l = list(signature.parameters)
|
l = list(signature.parameters)
|
||||||
self.assertEqual(l, unsorted_keyword_only_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):
|
class TestParameterObject(unittest.TestCase):
|
||||||
def test_signature_parameter_kinds(self):
|
def test_signature_parameter_kinds(self):
|
||||||
|
|
Loading…
Reference in New Issue