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

Python google_docstring not behaving with optional arguments #117

Closed
biojerm opened this issue Nov 15, 2022 · 4 comments · Fixed by #120
Closed

Python google_docstring not behaving with optional arguments #117

biojerm opened this issue Nov 15, 2022 · 4 comments · Fixed by #120
Labels
bug Something isn't working

Comments

@biojerm
Copy link

biojerm commented Nov 15, 2022

I am having issues where optional arguments are not behaving as expected when creating docstrings.

Scenario 1: no optional arguments

def duplicate(word: str, times: int) -> str:
    """
        word (str): 
        times (int): 

    Returns:
        
    """
    return word*times

Results: args are there, but the Args: header is missing. I would expect it based on the template definition. Not the end of the world, just noticed it was different

Scenario 2: optional argument, but no typing information.

def duplicate(word: str, times=1) -> str:
    """
        times (): 
        word (str): 

    Returns:
        
    """
    return word*times

Results: Args in wrong order, and missing type of optional argument.

Scenario 3: Typed optional arguments

def duplicate(word: str, times:int = 1) -> str:
    """
        word (str): 

    Returns:
        
    """
    return word*times

Results: typed optional argument completely missing.

Here is my config

neogen.setup{
    enabled = true,
    languages = {
        python = {
            template = {
                annotation_convention = "google_docstrings" -- for a full list of annotation_conventions, see supported-languages below,
                }
        },
    }
}

For reference this is the output I get, and would like to get close to, from VS code running autoDocstring

def duplicate(word: str, *, times=2) -> str:
    """_summary_

    Args:
        word (str): _description_
        times (int, optional): _description_. Defaults to 2.

    Returns:
        str: _description_
    """
    return word*times

I am running osX 12.6 Montery on an M1 Mac.

❯ nvim -v
NVIM v0.8.0

Any thoughts on what is happening? I tried to look at the google_docstring template but only understood about 20% of what was happening.

@danymat
Copy link
Owner

danymat commented Nov 15, 2022

Scenario 1:

Results: args are there, but the Args: header is missing. I would expect it based on the template definition. Not the end of the world, just noticed it was different

Indeed, it's a bug. I will fix it.

Scenario 2

Results: Args in wrong order, and missing type of optional argument.

This is actual behavior:

  • Args in wrong order: the order can sometimes not be respected if the type of parameter is not the same (mixing optional and required params). I gave some ideas on how to fix this, but will require some deep thinking that i can't allow to myself on the upcoming days. I will take a look as a next enhancement.
  • Missing type: indeed, this functionality of getting types via default values is not developed. I will add to the list, if you think that could be a great thing.

Scenario 3

Results: typed optional argument completely missing.

It's a bug, thanks for catching it!

Thank you for this great feedback, and I hope you still find value in this plugin while those features are still in the queue.

@biojerm
Copy link
Author

biojerm commented Nov 16, 2022

Yeah it is a great plug in. I looked at how the mapping works a bit more this morning and started to wrap my head around what is happening. My lua is a 1/10. So the difficulty is not coming from your code 😄 .

@danymat
Copy link
Owner

danymat commented Nov 17, 2022

Nevertheless, I don't think neogen could be complicated, but indeed it's complex.

A very good documentation alongside the actual code (even more because you're starting lua) is to check the help file:

:h neogen

Here, you'll get the philosophy, the idea behind code structure and how to understand/customize it

@danymat danymat added the bug Something isn't working label Dec 9, 2022
@danymat danymat linked a pull request Dec 27, 2022 that will close this issue
@danymat
Copy link
Owner

danymat commented Dec 27, 2022

Hello, sorry for the delay (and merry Christmas)

I created a PR to fix bug 1 and 3 that you provided.
Can you try and tell me if everything works fine ?
Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants