diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2017-11-15 18:30:59 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2017-11-15 18:30:59 (GMT) |
commit | 762b9571c9c8c6b036f1bf90140a1d030b3f9a01 (patch) | |
tree | 8aacee139aaa773259cc43300b09e911038b7380 | |
parent | f8a4c03ede6048022f60a58d5a21b278b78a8a16 (diff) | |
download | cpython-762b9571c9c8c6b036f1bf90140a1d030b3f9a01.zip cpython-762b9571c9c8c6b036f1bf90140a1d030b3f9a01.tar.gz cpython-762b9571c9c8c6b036f1bf90140a1d030b3f9a01.tar.bz2 |
bpo-32018: Fix inspect.signature repr to follow PEP 8 (#4408)
-rw-r--r-- | Lib/inspect.py | 7 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 4 | ||||
-rw-r--r-- | Lib/test/test_pydoc.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2017-11-16-02-32-41.bpo-32018.YMQ7Q2.rst | 2 |
4 files changed, 10 insertions, 5 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 6d6fde9..69f2b62 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2521,11 +2521,14 @@ class Parameter: # 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 diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index e64215d..13a86b1 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -2875,12 +2875,12 @@ class TestSignatureObject(unittest.TestCase): 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 diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 52830b4..2fa0893 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -824,7 +824,7 @@ class TestDescriptions(unittest.TestCase): 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)') diff --git a/Misc/NEWS.d/next/Library/2017-11-16-02-32-41.bpo-32018.YMQ7Q2.rst b/Misc/NEWS.d/next/Library/2017-11-16-02-32-41.bpo-32018.YMQ7Q2.rst new file mode 100644 index 0000000..aa8a47c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-11-16-02-32-41.bpo-32018.YMQ7Q2.rst @@ -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. |