mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Undo finding signatures for everything and only do it for stubs and non-statements for when used in docstrings
This commit is contained in:
@@ -247,7 +247,7 @@ class BaseDefinition(object):
|
|||||||
|
|
||||||
signature_text = '\n'.join(
|
signature_text = '\n'.join(
|
||||||
signature.to_string()
|
signature.to_string()
|
||||||
for signature in self._get_signatures()
|
for signature in self._get_signatures(for_docstring=True)
|
||||||
)
|
)
|
||||||
if signature_text and doc:
|
if signature_text and doc:
|
||||||
return signature_text + '\n\n' + doc
|
return signature_text + '\n\n' + doc
|
||||||
@@ -484,7 +484,12 @@ class BaseDefinition(object):
|
|||||||
start_index = max(index - before, 0)
|
start_index = max(index - before, 0)
|
||||||
return ''.join(lines[start_index:index + after + 1])
|
return ''.join(lines[start_index:index + after + 1])
|
||||||
|
|
||||||
def _get_signatures(self):
|
def _get_signatures(self, for_docstring=False):
|
||||||
|
if for_docstring and self.type == 'statement' and not self.is_stub():
|
||||||
|
# For docstrings we don't resolve signatures if they are simple
|
||||||
|
# statements and not stubs. This is a speed optimization.
|
||||||
|
return []
|
||||||
|
|
||||||
names = convert_names([self._name], prefer_stubs=True)
|
names = convert_names([self._name], prefer_stubs=True)
|
||||||
return [sig for name in names for sig in name.infer().get_signatures()]
|
return [sig for name in names for sig in name.infer().get_signatures()]
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ def test_help_no_returns(Script, code, kwargs):
|
|||||||
('X.x', 'Yeah '),
|
('X.x', 'Yeah '),
|
||||||
('X().x', 'Yeah '),
|
('X().x', 'Yeah '),
|
||||||
('X.y', 'f g '),
|
('X.y', 'f g '),
|
||||||
('X.z', '<lambda>(x)'),
|
('X.z', ''),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_attribute_docstrings(goto_or_help, expected_doc, to_execute):
|
def test_attribute_docstrings(goto_or_help, expected_doc, to_execute):
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ def test_multiple_docstrings(Script):
|
|||||||
x = func
|
x = func
|
||||||
'''Docstring of `x`.'''
|
'''Docstring of `x`.'''
|
||||||
x""").help()
|
x""").help()
|
||||||
assert d.docstring() == 'func()\n\nDocstring of `x`.'
|
assert d.docstring() == 'Docstring of `x`.'
|
||||||
|
|
||||||
|
|
||||||
def test_completion(Script):
|
def test_completion(Script):
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ def test_find_stubs_infer(ScriptInStubFolder, code, expected):
|
|||||||
assert [d.name for d in defs] == expected
|
assert [d.name for d in defs] == expected
|
||||||
|
|
||||||
|
|
||||||
func_without_stub_sig = 'func_without_stub(a)'
|
func_without_stub_doc = 'func_without_stub(a)\n\nnostubdoc'
|
||||||
func_without_stub_doc = func_without_stub_sig + '\n\nnostubdoc'
|
|
||||||
func_with_stub_doc = 'func_with_stub(b: int) -> float\n\nwithstubdoc'
|
func_with_stub_doc = 'func_with_stub(b: int) -> float\n\nwithstubdoc'
|
||||||
|
|
||||||
|
|
||||||
@@ -38,16 +37,16 @@ func_with_stub_doc = 'func_with_stub(b: int) -> float\n\nwithstubdoc'
|
|||||||
('from with_python import python_only', ''),
|
('from with_python import python_only', ''),
|
||||||
('from with_python import both', ''),
|
('from with_python import both', ''),
|
||||||
|
|
||||||
('import with_python; with_python.func_without_stub', func_without_stub_sig),
|
('import with_python; with_python.func_without_stub', ''),
|
||||||
('import with_python.module; with_python.module.func_without_stub', func_without_stub_doc),
|
('import with_python.module; with_python.module.func_without_stub', func_without_stub_doc),
|
||||||
('from with_python import module; module.func_without_stub', func_without_stub_doc),
|
('from with_python import module; module.func_without_stub', func_without_stub_doc),
|
||||||
('from with_python.module import func_without_stub', func_without_stub_doc),
|
('from with_python.module import func_without_stub', func_without_stub_doc),
|
||||||
('from with_python.module import func_without_stub as f; f', func_without_stub_doc),
|
('from with_python.module import func_without_stub as f; f', func_without_stub_doc),
|
||||||
('from with_python.module import func_without_stub; func_without_stub',
|
('from with_python.module import func_without_stub; func_without_stub',
|
||||||
func_without_stub_doc),
|
func_without_stub_doc),
|
||||||
('from with_python import func_without_stub', func_without_stub_sig),
|
('from with_python import func_without_stub', ''),
|
||||||
('from with_python import func_without_stub as f; f', func_without_stub_sig),
|
('from with_python import func_without_stub as f; f', ''),
|
||||||
('from with_python import func_without_stub; func_without_stub', func_without_stub_sig),
|
('from with_python import func_without_stub; func_without_stub', ''),
|
||||||
|
|
||||||
('import with_python; with_python.func_with_stub', func_with_stub_doc),
|
('import with_python; with_python.func_with_stub', func_with_stub_doc),
|
||||||
('import with_python.module; with_python.module.func_with_stub', func_with_stub_doc),
|
('import with_python.module; with_python.module.func_with_stub', func_with_stub_doc),
|
||||||
|
|||||||
Reference in New Issue
Block a user