docstr
docstr copied to clipboard
split param-string by escaping brackets to allow for type containing brackets
Types in Python might contain brackets and commas resulting in errors when parsing the parameters of the function.
Example
def foo(bar: Dict[str, Dict[str, str]]) -> Dict[str, Dict[str, str]]:
pass
Results in
The PR creates a new function docstr--split-string-escape-brackets
that split string while escaping the bracket to capture the full type:
I don't think it will work since it will affect all other languages. Python is indeed one of the hardest languages to parse using regex. 😓
Another approach is ts-docstr, but it requires tree-sitter. The parsing task is a lot easier there, and it's fast and accurate. Here is the result from ts-docstr
:
def foo(bar: Dic[str, Dict[str, str]]) -> Dict[str, Dict[str, str]]:
"""
Parameters
-------
bar : Dic[str, Dict[str, str]]
[description]
Returns
-------
[description]
"""
pass
Hi @jcs090218, thank you for the swift reply. True that it will affect other languages but I think it's harmless as I cannot think of a programming language that would use unclosed brackets as part of a type or variable name - do you have an example in mind ?
Happy to use ts-docstr
but it has some dependency to some niche packages like msgu
which cannot be found on the usual Emacs lisp package archives.
True that it will affect other languages but I think it's harmless as I cannot think of a programming language that would use unclosed brackets as part of a type or variable name - do you have an example in mind ?
I don't have an example in mind. Let me re-think this, and then I will get back to you!
Happy to use ts-docstr but it has some dependency to some niche packages like msgu which cannot be found on the usual Emacs lisp package archives.
msgu
is under my own JCS-ELPA, including the package ts-docstr
.