Type annotations cause converted docstrings to break
Edit:
It seems this has been fixed in this repo, but on the version from PyPi does not include this fix. I was able to install from source to resolve the issue.
I'm trying to convert docstrings from reST to Google format but the output is broken in functions with type annotations.
Example input file foo.py
from typing import Tuple, Optional
# With type annotations (Broken)
def foo(bar: int, baz: Tuple[int, str], qux: Optional[int] = None) -> str:
"""
Main description.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis molestie
neque ac dolor hendrerit molestie. Integer eu placerat nisl. Ut vel tellus sem.
Nunc ornare ultrices quam, at venenatis est blandit sed.
:param bar: does a bar
:type bar: int
:param baz: does a baz
:type baz: Tuple[int, str]
:param qux: does a qux
:type qux: Optional[int]
:returns: hello world
:rtype: str
"""
return "Hello world"
# No type annotations (working)
def bar(bar, baz, qux = None) -> str:
"""
Main description.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis molestie
neque ac dolor hendrerit molestie. Integer eu placerat nisl. Ut vel tellus sem.
Nunc ornare ultrices quam, at venenatis est blandit sed.
:param bar: does a bar
:type bar: int
:param baz: does a baz
:type baz: Tuple[int, str]
:param qux: does a qux
:type qux: Optional[int]
:returns: hello world
:rtype: str
"""
return "Hello world"
Then, we run the command
pyment -i reST -o google -w foo.py
and we get the resulting file:
from typing import Tuple, Optional
# With type annotations (Broken)
def foo(bar: int, baz: Tuple[int, str], qux: Optional[int] = None) -> str:
"""Main description.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis molestie
neque ac dolor hendrerit molestie. Integer eu placerat nisl. Ut vel tellus sem.
Nunc ornare ultrices quam, at venenatis est blandit sed.
Args:
bar(int): does a bar
baz(Tuple[int, str]): does a baz
qux(Optional[int]): does a qux
bar: int:
baz: Tuple[int:
str]:
qux: Optional[int]: (Default value = None)
Returns:
str: hello world
"""
return "Hello world"
# No type annotations (working)
def bar(bar, baz, qux = None) -> str:
"""Main description.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis molestie
neque ac dolor hendrerit molestie. Integer eu placerat nisl. Ut vel tellus sem.
Nunc ornare ultrices quam, at venenatis est blandit sed.
Args:
bar(int): does a bar
baz(Tuple[int, str]): does a baz
qux(Optional[int], optional): does a qux (Default value = None)
Returns:
str: hello world
"""
return "Hello world"
In the resulting file the type annotated function has extra lines added for each parameter. Additionally, the default value is placed on the extraneous line.
I have the same problem for the pyment installed in conda.
Problem still persist, but I am not sure if pyment is currently under active development (see #111)