Skip to content

bpo-32018: inspect.signature should follow PEP 8 #4408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2521,11 +2521,14 @@ def __str__(self):

# Add annotation and default value
if self._annotation is not _empty:
formatted = '{}:{}'.format(formatted,
formatted = '{}: {}'.format(formatted,
formatannotation(self._annotation))

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:
formatted = '*' + formatted
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2875,12 +2875,12 @@ def test_signature_str(self):
def foo(a:int=1, *, b, c=None, **kwargs) -> 42:
pass
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:
pass
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():
pass
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def foo(data: typing.List[typing.Any],
T = typing.TypeVar('T')
class C(typing.Generic[T], typing.Mapping[int, str]): ...
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]]')
self.assertEqual(pydoc.render_doc(C).splitlines()[2],
'class C\x08C(typing.Mapping)')
Expand Down
Original file line number Diff line number Diff line change
@@ -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.