autoDocstring
autoDocstring copied to clipboard
Parameters are omitted when parameter has a default string containing python "reserved" words
Describe the bug Can't generate right doc string (parameters are omitted) when parameter has a default string containing python "reserved" words(like "class", "def", etc.)
Versions (please complete the following information):
- autoDocstring Version: v0.5.4
- Operating System: macOS Catalina 10.15.6 (19G2021)
- Vscode Version: 1.56.2
Original Code (with line to generate on):
def not_work(a="class"):
pass
def work(a="clazz"):
pass
Expected Result:
def not_work(a="class"):
"""[summary]
Args:
a (str, optional): [description]. Defaults to "class".
"""
pass
def work(a="clazz"):
"""[summary]
Args:
a (str, optional): [description]. Defaults to "clazz".
"""
pass
Actual Result:
def not_work(a="class"):
"""[summary]
"""
pass
def work(a="clazz"):
"""[summary]
Args:
a (str, optional): [description]. Defaults to "clazz".
"""
pass
Stack trace:
If an error was reported by autodocstring please copy the stack trace from the autoDocstring output channel.
no error was reported
Additional context No additional context.
I've identified where the bug is occurring but I don't totally understand all of the context for why things are being done the way they are.
When the function definition is being obtained, all the previous lines up to the current cursor position are considered, then the last instance of class or def is chosen. I'm not sure why all of that previous context is necessary. Potentially to ensure the entire definition is captured when it is split across multiple lines.
Regardless, there in lies the problem, the last instance of class or def is selected, so if the default value is class or def, the definition for the function becomes class"): which obviously breaks the rest of the parsing.
https://github.com/NilsJPWerner/autoDocstring/blob/9c6ed72689195ca17d94f7dd04c5ae3ba4bc4eb2/src/parse/get_definition.ts#L3-L27