bpo-32018: Fix inspect.signature repr to follow PEP 8 (#4408)
This commit is contained in:
parent
f8a4c03ede
commit
762b9571c9
|
@ -2521,11 +2521,14 @@ class Parameter:
|
||||||
|
|
||||||
# Add annotation and default value
|
# Add annotation and default value
|
||||||
if self._annotation is not _empty:
|
if self._annotation is not _empty:
|
||||||
formatted = '{}:{}'.format(formatted,
|
formatted = '{}: {}'.format(formatted,
|
||||||
formatannotation(self._annotation))
|
formatannotation(self._annotation))
|
||||||
|
|
||||||
if self._default is not _empty:
|
if self._default is not _empty:
|
||||||
formatted = '{}={}'.format(formatted, repr(self._default))
|
if self._annotation is not _empty:
|
||||||
|
formatted = '{} = {}'.format(formatted, repr(self._default))
|
||||||
|
else:
|
||||||
|
formatted = '{}={}'.format(formatted, repr(self._default))
|
||||||
|
|
||||||
if kind == _VAR_POSITIONAL:
|
if kind == _VAR_POSITIONAL:
|
||||||
formatted = '*' + formatted
|
formatted = '*' + formatted
|
||||||
|
|
|
@ -2875,12 +2875,12 @@ class TestSignatureObject(unittest.TestCase):
|
||||||
def foo(a:int=1, *, b, c=None, **kwargs) -> 42:
|
def foo(a:int=1, *, b, c=None, **kwargs) -> 42:
|
||||||
pass
|
pass
|
||||||
self.assertEqual(str(inspect.signature(foo)),
|
self.assertEqual(str(inspect.signature(foo)),
|
||||||
'(a:int=1, *, b, c=None, **kwargs) -> 42')
|
'(a: int = 1, *, b, c=None, **kwargs) -> 42')
|
||||||
|
|
||||||
def foo(a:int=1, *args, b, c=None, **kwargs) -> 42:
|
def foo(a:int=1, *args, b, c=None, **kwargs) -> 42:
|
||||||
pass
|
pass
|
||||||
self.assertEqual(str(inspect.signature(foo)),
|
self.assertEqual(str(inspect.signature(foo)),
|
||||||
'(a:int=1, *args, b, c=None, **kwargs) -> 42')
|
'(a: int = 1, *args, b, c=None, **kwargs) -> 42')
|
||||||
|
|
||||||
def foo():
|
def foo():
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -824,7 +824,7 @@ class TestDescriptions(unittest.TestCase):
|
||||||
T = typing.TypeVar('T')
|
T = typing.TypeVar('T')
|
||||||
class C(typing.Generic[T], typing.Mapping[int, str]): ...
|
class C(typing.Generic[T], typing.Mapping[int, str]): ...
|
||||||
self.assertEqual(pydoc.render_doc(foo).splitlines()[-1],
|
self.assertEqual(pydoc.render_doc(foo).splitlines()[-1],
|
||||||
'f\x08fo\x08oo\x08o(data:List[Any], x:int)'
|
'f\x08fo\x08oo\x08o(data: List[Any], x: int)'
|
||||||
' -> Iterator[Tuple[int, Any]]')
|
' -> Iterator[Tuple[int, Any]]')
|
||||||
self.assertEqual(pydoc.render_doc(C).splitlines()[2],
|
self.assertEqual(pydoc.render_doc(C).splitlines()[2],
|
||||||
'class C\x08C(typing.Mapping)')
|
'class C\x08C(typing.Mapping)')
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
inspect.signature should follow PEP 8, if the parameter has an annotation and a
|
||||||
|
default value. Patch by Dong-hee Na.
|
Loading…
Reference in New Issue