autoDocstring
autoDocstring copied to clipboard
Yield and Return parsing seems too eager
Describe the bug
The docstring indicates that a function yields or returns whenever there is a variable/command in the function that ends with the word "yield" or "return", even if this is just a variable e.g. named strength_yield or preturn.
Versions (please complete the following information):
- autoDocstring Version:0.6.1
- Operating System: Windows Server 2016 version 1607
- Vscode Version: 1.87.0
Original Code (with line to generate on):
def no_yield_func(a, b):
# generate on this line
result = a*b
strength_yield = 5
return result
Expected Result:
"""_summary_
Parameters
----------
a : _type_
_description_
b : _type_
_description_
Returns
-------
_type_
_description_
"""
Actual Result:
"""_summary_
Parameters
----------
a : _type_
_description_
b : _type_
_description_
Returns
-------
_type_
_description_
Yields
------
_type_
_description_
"""
Debug log:
Set autoDocstring.logLevel to "Debug", recreate the bug, and then copy the debug logs from the autoDocstring output channel.
[INFO 11:44:45.529] Generating Docstring at line: 6
[DEBUG 11:44:45.530] DocstringFactory Configuration
quoteStyle:
"""
startOnNewLine:
false
guessTypes:
true
includeName:
false
includeDescription:
false
template:
{{! Numpy Docstring Template }}
{{summaryPlaceholder}}
{{extendedSummaryPlaceholder}}
{{#parametersExist}}
Parameters
----------
{{#args}}
{{var}} : {{typePlaceholder}}
{{descriptionPlaceholder}}
{{/args}}
{{#kwargs}}
{{var}} : {{typePlaceholder}}, optional
{{descriptionPlaceholder}}, by default {{&default}}
{{/kwargs}}
{{/parametersExist}}
{{#returnsExist}}
Returns
-------
{{#returns}}
{{typePlaceholder}}
{{descriptionPlaceholder}}
{{/returns}}
{{/returnsExist}}
{{#yieldsExist}}
Yields
------
{{#yields}}
{{typePlaceholder}}
{{descriptionPlaceholder}}
{{/yields}}
{{/yieldsExist}}
{{#exceptionsExist}}
Raises
------
{{#exceptions}}
{{type}}
{{descriptionPlaceholder}}
{{/exceptions}}
{{/exceptionsExist}}
[DEBUG 11:44:45.532] Docstring parts:
Name:
no_yield_func
Decorators:
N/A
Args:
a undefined
b undefined
Kwargs:
N/A
Exceptions:
N/A
Returns:
N/A
Yields:
N/A
[DEBUG 11:44:45.532] Default indentation: " "
[DEBUG 11:44:45.532] Indentation: " "
[INFO 11:44:45.534] Docstring generated:
"""${1:_summary_}
Parameters
----------
a : ${2:_type_}
${3:_description_}
b : ${4:_type_}
${5:_description_}
Returns
-------
${6:_type_}
${7:_description_}
Yields
------
${8:_type_}
${9:_description_}
"""
[INFO 11:44:45.535] Inserting at position: 6 0
[INFO 11:44:45.542] Successfully inserted docstring
Stack trace:
If an error was reported by autoDocstring please copy the stack trace from the autoDocstring output channel.
N/A
Additional context
I'm not entirely sure, but I think this can be resolved by changing the regex in the parseFromBody call in the parseYields function