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

Added google/napoleon docstring support to fix #504 #617

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions jedi/evaluate/docstrings.py
Expand Up @@ -29,11 +29,13 @@
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
r'\s*:param\s+(\w+)\s+%s:[^\n]+', # Sphinx param with type
r'\s*@type\s+%s:\s*([^\n]+)', # Epydoc
'\s*%s\s*\((.+?)\):.+', # Google param with type
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't check for Args. Shouldn't we do that? Otherwise it might just much

Also I don't think you need .+.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's basically a context free language which would require to count the parenthesis, since that's not possible in a regular language it seemed like .+? would be the best solution here. We could try everything except for : instead but I'm not sure that will work correctly in all cases.

As for the Args, while not impossible, that would require a fairly large rewrite. The entire _search_param_in_docstr function wouldn't be usable anymore as it's only allowed to match using this regex when Args: precedes it. Or have I missed something in the code that would easily allow for this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's basically a context free language

I understand that, but you could check it before hand. That makes it a little bit more complicated (in the Python area), but could still work. Obviously modifying regexes would not be enough anymore.

]

DOCSTRING_RETURN_PATTERNS = [
re.compile(r'\s*:rtype:\s*([^\n]+)', re.M), # Sphinx
re.compile(r'\s*@rtype:\s*([^\n]+)', re.M), # Epydoc
re.compile(r'\s*Returns:\s*([^:]+):.*', re.M), # Google
]

REST_ROLE_PATTERN = re.compile(r':[^`]+:`([^`]+)`')
Expand Down Expand Up @@ -77,6 +79,10 @@ def _search_param_in_docstr(docstr, param_str):
False
>>> _search_param_in_docstr(':param int param: some description', 'param')
['int']
>>> _search_param_in_docstr('param (int): doc', 'param')
['int']
>>> _search_param_in_docstr('param: doc', 'param')
[]

"""
# look at #40 to see definitions of those params
Expand Down
38 changes: 35 additions & 3 deletions test/completion/docstring.py
Expand Up @@ -39,16 +39,48 @@ def sphinxy2(a, b, x):
:param x: Just something without type
:rtype:
"""
#?
#?
a
#?
#?
b
#?
x

#?
#?
sphinxy2()

# -----------------
# google style
# -----------------
def sphinx_google(a, b, c, d, x):
""" asdfasdf

Args:
a (str): blablabla
b (str, int): b
c (random.Random): c
d (random.Random): d
x: blablabla

Returns:
dict: Some dict
"""
#? str()
a
#? str()
b[0]
#? int()
b[1]
#? ['seed']
c.seed
#? ['seed']
d.seed
#?
x.lower

#? dict()
sphinx_google()

# local classes -> github #370
class ProgramNode():
pass
Expand Down