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

Fix keyword docstring #941

Merged
merged 1 commit into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions jedi/api/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ class KeywordName(AbstractNameDefinition):
api_type = 'keyword'

def __init__(self, evaluator, name):
self.evaluator = evaluator
self.string_name = name
self.parent_context = evaluator.BUILTINS

def eval(self):
return set()

def infer(self):
return [Keyword(self.evaluator, self.string_name, (0, 0))]


class Keyword(object):
api_type = 'keyword'
Expand All @@ -100,9 +104,8 @@ def names(self):
""" For a `parsing.Name` like comparision """
return [self.name]

@property
def docstr(self):
return imitate_pydoc(self.name)
def py__doc__(self, include_call_signature=False):
return imitate_pydoc(self.name.string_name)

def __repr__(self):
return '<%s: %s>' % (type(self).__name__, self.name)
Expand Down Expand Up @@ -136,6 +139,6 @@ def imitate_pydoc(string):
return ''

try:
return pydoc_topics.topics[label] if pydoc_topics else ''
return pydoc_topics.topics[label].strip() if pydoc_topics else ''
except KeyError:
return ''
10 changes: 7 additions & 3 deletions test/test_evaluate/test_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def test_function_doc(self):
def func():
'''Docstring of `func`.'''
func""").goto_definitions()
self.assertEqual(defs[0].raw_doc, 'Docstring of `func`.')
self.assertEqual(defs[0].docstring(), 'func()\n\nDocstring of `func`.')

@unittest.skip('need evaluator class for that')
def test_attribute_docstring(self):
defs = jedi.Script("""
x = None
'''Docstring of `x`.'''
x""").goto_definitions()
self.assertEqual(defs[0].raw_doc, 'Docstring of `x`.')
self.assertEqual(defs[0].docstring(), 'Docstring of `x`.')

@unittest.skip('need evaluator class for that')
def test_multiple_docstrings(self):
Expand All @@ -38,7 +38,7 @@ def func():
x = func
'''Docstring of `x`.'''
x""").goto_definitions()
docs = [d.raw_doc for d in defs]
docs = [d.docstring() for d in defs]
self.assertEqual(docs, ['Original docstring.', 'Docstring of `x`.'])

def test_completion(self):
Expand Down Expand Up @@ -105,6 +105,10 @@ def method_b(c):
assert '__init__' in names
assert 'mro' not in names # Exists only for types.

def test_docstring_keyword(self):
completions = jedi.Script('assert').completions()
self.assertIn('assert', completions[0].docstring())

@unittest.skipIf(numpydoc_unavailable, 'numpydoc module is unavailable')
def test_numpydoc_docstring(self):
s = dedent('''
Expand Down