sourcegraph / cody

Type less, code more: Cody is an AI code assistant that uses advanced search and codebase context to help you write and fix code.
https://cody.dev
Apache License 2.0
2.59k stars 275 forks source link

bug: python: docstring generation breaks code #3251

Closed bellerofonte closed 2 months ago

bellerofonte commented 7 months ago

Version

v1.6.0

Describe the bug

When I ask Cody to generate a docstring for my python code it generates a good text but puts it on wrong spot with wrong alignment.

For example:

def SomeClass(object):
     def some_method(self):
        pass

if I select a piece of code, f.e. some_method and run Cody Command: Document Code I get this:

def SomeClass(object):
        """Returns y multiplied by x plus 1.

    Args:
        x: The first number to multiply.
        y: The second number to multiply.

    Returns:
        The product of y * (x + 1).
    """
def some_method(self, x, y):
        return y * (x + 1)

the first thing to notice here is that alignment is broken between the second line of the docstring and the method definition.

the second thing to notice - if the alignment were right, this still does not comply with PEP 257 which stands for:

def method_name(params):
    """Method description.

    Extended description and details.
    """
    # method body

Expected behavior

def SomeClass(object):
    def some_method(self, x, y):
        """Returns y multiplied by x plus 1.

        Args:
            x: The first number to multiply.
            y: The second number to multiply.

        Returns:
            The product of y * (x + 1).
        """
        return y * (x + 1)

Additional context

No response

github-actions[bot] commented 3 months ago

This issue is marked as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed automatically in 5 days.