autoDocstring icon indicating copy to clipboard operation
autoDocstring copied to clipboard

Non ASCI variable names cause insufficient docstring generation

Open Coronon opened this issue 4 years ago • 1 comments
trafficstars

Describe the bug When creating a docstring, function parameters, their types and the return-type is not taken into consideration. The generated docstring will only contain a seemingly random selection of required tags. This seems to be a problem with custom, non ASCI, characters.

Versions (please complete the following information):

  • autoDocstring Version: v0.5.4
  • Operating System: Windows
  • Vscode Version: 1.54.3
  • Environment: Remote VSCode -> Ubuntu over SSH (Yes, also installed and activated for the remote)

Original Code (with line to generate on):

def create_device(user: Union[Benutzer, str], name: str, info: str="{}") -> Optional[Gerät]:
     # generate on this line

Expected Result:

"""[summary]

Arguments:
    username {Union[Benutzer, str]} -- [description]
    name {str} -- [description]
    info {str} -- [description] (default: {"{}"})

Returns:
    Optional[Gerät] -- [description]
"""

Actual Result:

"""[summary]

Returns:
    [type] -- [description]
"""

-> Sometimes the 'Returns' is included, sometimes not (even with the exact same return-types). For example:

def get_associated_device(user: Union[Benutzer, str], info: dict) -> Optional[Gerät]:

Would only generate:

"""[summary]
"""

Logs:

[INFO 15:34:07.637] Generating Docstring at line: 83
[INFO 15:34:07.639] Docstring generated:
    """${1:[summary]}

    Returns:
        ${2:[type]} -- ${3:[description]}
    """
[INFO 15:34:07.639] Inserting at position: 83 0
[INFO 15:34:07.690] Successfully inserted docstring

...

[INFO 15:39:17.599] Generating Docstring at line: 107
[INFO 15:39:17.602] Docstring generated:
    """${1:[summary]}
    """
[INFO 15:39:17.602] Inserting at position: 107 0
[INFO 15:39:17.640] Successfully inserted docstring

Additional context Python does support non ASCII Characters in identifiers. I always stayed away from them but this time I figured my code would be easier to read if I used them in a few parts (at least for Germans) and ran into this bug. The code is perfectly fine and runs like a charm, but I really miss the convenience this extension brings.

Keep up the great work!

PS: In just a little look at the source code I already found this line: https://github.com/NilsJPWerner/autoDocstring/blob/922a5e7a1cd4ef9a23c6a218254b315f0efe5ff1/src/parse/guess_type.ts#L15-L17

The Regex seems insufficient for non ASCI type names

Coronon avatar Mar 30 '21 15:03 Coronon