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

split param-string by escaping brackets to allow for type containing brackets #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

louisdecharson
Copy link

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
image

The PR creates a new function docstr--split-string-escape-brackets that split string while escaping the bracket to capture the full type:
image

@jcs090218
Copy link
Member

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

@louisdecharson
Copy link
Author

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.

@jcs090218
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants