Skip to content
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

Type annotations cause converted docstrings to break #104

Open
cubrink opened this issue May 26, 2021 · 2 comments
Open

Type annotations cause converted docstrings to break #104

cubrink opened this issue May 26, 2021 · 2 comments

Comments

@cubrink
Copy link

cubrink commented May 26, 2021

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.

@andreikee
Copy link

I have the same problem for the pyment installed in conda.

@stangier
Copy link

Problem still persist, but I am not sure if pyment is currently under active development (see #111)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants