Include function return type annotation in docstring if it is present

This commit is contained in:
Dima Gerasimov
2018-03-05 18:24:28 +00:00
committed by Dave Halter
parent 88243d2408
commit ceb5509170
3 changed files with 8 additions and 2 deletions

View File

@@ -50,5 +50,6 @@ Anton Zub (@zabulazza)
Maksim Novikov (@m-novikov) <mnovikov.work@gmail.com> Maksim Novikov (@m-novikov) <mnovikov.work@gmail.com>
Tobias Rzepka (@TobiasRzepka) Tobias Rzepka (@TobiasRzepka)
micbou (@micbou) micbou (@micbou)
Dima Gerasimov (@karlicoss) <karlicoss@gmail.com>
Note: (@user) means a github user name. Note: (@user) means a github user name.

View File

@@ -156,7 +156,11 @@ def get_call_signature(funcdef, width=72, call_string=None):
p = '(' + ''.join(param.get_code() for param in funcdef.get_params()).strip() + ')' p = '(' + ''.join(param.get_code() for param in funcdef.get_params()).strip() + ')'
else: else:
p = funcdef.children[2].get_code() p = funcdef.children[2].get_code()
code = call_string + p if funcdef.annotation:
rtype = " ->" + funcdef.annotation.get_code()
else:
rtype = ""
code = call_string + p + rtype
return '\n'.join(textwrap.wrap(code, width)) return '\n'.join(textwrap.wrap(code, width))

View File

@@ -75,7 +75,8 @@ def test_hex_values_in_docstring():
@pytest.mark.parametrize( @pytest.mark.parametrize(
'code,call_signature', [ 'code,call_signature', [
('def my_function(x, y, z) -> str:\n return', 'my_function(x, y, z)'), ('def my_function(x, typed: Type, z):\n return', 'my_function(x, typed: Type, z)'),
('def my_function(x, y, z) -> str:\n return', 'my_function(x, y, z) -> str'),
('lambda x, y, z: x + y * z\n', '<lambda>(x, y, z)') ('lambda x, y, z: x + y * z\n', '<lambda>(x, y, z)')
]) ])
def test_get_call_signature(code, call_signature): def test_get_call_signature(code, call_signature):