mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-18 14:29:40 +08:00
Merge branch 'dev' of github.com:davidhalter/jedi into dev
This commit is contained in:
@@ -76,12 +76,16 @@ class KeywordName(AbstractNameDefinition):
|
|||||||
api_type = 'keyword'
|
api_type = 'keyword'
|
||||||
|
|
||||||
def __init__(self, evaluator, name):
|
def __init__(self, evaluator, name):
|
||||||
|
self.evaluator = evaluator
|
||||||
self.string_name = name
|
self.string_name = name
|
||||||
self.parent_context = evaluator.BUILTINS
|
self.parent_context = evaluator.BUILTINS
|
||||||
|
|
||||||
def eval(self):
|
def eval(self):
|
||||||
return set()
|
return set()
|
||||||
|
|
||||||
|
def infer(self):
|
||||||
|
return [Keyword(self.evaluator, self.string_name, (0, 0))]
|
||||||
|
|
||||||
|
|
||||||
class Keyword(object):
|
class Keyword(object):
|
||||||
api_type = 'keyword'
|
api_type = 'keyword'
|
||||||
@@ -100,9 +104,8 @@ class Keyword(object):
|
|||||||
""" For a `parsing.Name` like comparision """
|
""" For a `parsing.Name` like comparision """
|
||||||
return [self.name]
|
return [self.name]
|
||||||
|
|
||||||
@property
|
def py__doc__(self, include_call_signature=False):
|
||||||
def docstr(self):
|
return imitate_pydoc(self.name.string_name)
|
||||||
return imitate_pydoc(self.name)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self.name)
|
return '<%s: %s>' % (type(self).__name__, self.name)
|
||||||
@@ -136,6 +139,6 @@ def imitate_pydoc(string):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return pydoc_topics.topics[label] if pydoc_topics else ''
|
return pydoc_topics.topics[label].strip() if pydoc_topics else ''
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return ''
|
return ''
|
||||||
|
|||||||
@@ -197,6 +197,11 @@ class CompiledInstance(AbstractInstanceContext):
|
|||||||
|
|
||||||
|
|
||||||
class TreeInstance(AbstractInstanceContext):
|
class TreeInstance(AbstractInstanceContext):
|
||||||
|
def __init__(self, evaluator, parent_context, class_context, var_args):
|
||||||
|
super(TreeInstance, self).__init__(evaluator, parent_context,
|
||||||
|
class_context, var_args)
|
||||||
|
self.tree_node = class_context.tree_node
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return filters.ContextName(self, self.class_context.name.tree_name)
|
return filters.ContextName(self, self.class_context.name.tree_name)
|
||||||
|
|||||||
@@ -20,7 +20,22 @@ class TestDocstring(unittest.TestCase):
|
|||||||
def func():
|
def func():
|
||||||
'''Docstring of `func`.'''
|
'''Docstring of `func`.'''
|
||||||
func""").goto_definitions()
|
func""").goto_definitions()
|
||||||
self.assertEqual(defs[0].raw_doc, 'Docstring of `func`.')
|
self.assertEqual(defs[0].docstring(), 'func()\n\nDocstring of `func`.')
|
||||||
|
|
||||||
|
def test_class_doc(self):
|
||||||
|
defs = jedi.Script("""
|
||||||
|
class TestClass():
|
||||||
|
'''Docstring of `TestClass`.'''
|
||||||
|
TestClass""").goto_definitions()
|
||||||
|
self.assertEqual(defs[0].docstring(), 'Docstring of `TestClass`.')
|
||||||
|
|
||||||
|
def test_instance_doc(self):
|
||||||
|
defs = jedi.Script("""
|
||||||
|
class TestClass():
|
||||||
|
'''Docstring of `TestClass`.'''
|
||||||
|
tc = TestClass()
|
||||||
|
tc""").goto_definitions()
|
||||||
|
self.assertEqual(defs[0].docstring(), 'Docstring of `TestClass`.')
|
||||||
|
|
||||||
@unittest.skip('need evaluator class for that')
|
@unittest.skip('need evaluator class for that')
|
||||||
def test_attribute_docstring(self):
|
def test_attribute_docstring(self):
|
||||||
@@ -28,7 +43,7 @@ class TestDocstring(unittest.TestCase):
|
|||||||
x = None
|
x = None
|
||||||
'''Docstring of `x`.'''
|
'''Docstring of `x`.'''
|
||||||
x""").goto_definitions()
|
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')
|
@unittest.skip('need evaluator class for that')
|
||||||
def test_multiple_docstrings(self):
|
def test_multiple_docstrings(self):
|
||||||
@@ -38,7 +53,7 @@ class TestDocstring(unittest.TestCase):
|
|||||||
x = func
|
x = func
|
||||||
'''Docstring of `x`.'''
|
'''Docstring of `x`.'''
|
||||||
x""").goto_definitions()
|
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`.'])
|
self.assertEqual(docs, ['Original docstring.', 'Docstring of `x`.'])
|
||||||
|
|
||||||
def test_completion(self):
|
def test_completion(self):
|
||||||
@@ -105,6 +120,10 @@ class TestDocstring(unittest.TestCase):
|
|||||||
assert '__init__' in names
|
assert '__init__' in names
|
||||||
assert 'mro' not in names # Exists only for types.
|
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')
|
@unittest.skipIf(numpydoc_unavailable, 'numpydoc module is unavailable')
|
||||||
def test_numpydoc_docstring(self):
|
def test_numpydoc_docstring(self):
|
||||||
s = dedent('''
|
s = dedent('''
|
||||||
|
|||||||
Reference in New Issue
Block a user