mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Fix stub conversion for Decoratee, so docstrings work, see #117
This commit is contained in:
@@ -4,6 +4,7 @@ from jedi.inference.base_value import ValueSet, \
|
|||||||
from jedi.inference.utils import to_list
|
from jedi.inference.utils import to_list
|
||||||
from jedi.inference.gradual.stub_value import StubModuleValue
|
from jedi.inference.gradual.stub_value import StubModuleValue
|
||||||
from jedi.inference.gradual.typeshed import try_to_load_stub_cached
|
from jedi.inference.gradual.typeshed import try_to_load_stub_cached
|
||||||
|
from jedi.inference.value.decorator import Decoratee
|
||||||
|
|
||||||
|
|
||||||
def _stub_to_python_value_set(stub_value, ignore_compiled=False):
|
def _stub_to_python_value_set(stub_value, ignore_compiled=False):
|
||||||
@@ -11,6 +12,10 @@ def _stub_to_python_value_set(stub_value, ignore_compiled=False):
|
|||||||
if not stub_module_context.is_stub():
|
if not stub_module_context.is_stub():
|
||||||
return ValueSet([stub_value])
|
return ValueSet([stub_value])
|
||||||
|
|
||||||
|
decorates = None
|
||||||
|
if isinstance(stub_value, Decoratee):
|
||||||
|
decorates = stub_value._original_value
|
||||||
|
|
||||||
was_instance = stub_value.is_instance()
|
was_instance = stub_value.is_instance()
|
||||||
if was_instance:
|
if was_instance:
|
||||||
stub_value = stub_value.py__class__()
|
stub_value = stub_value.py__class__()
|
||||||
@@ -37,6 +42,8 @@ def _stub_to_python_value_set(stub_value, ignore_compiled=False):
|
|||||||
# Now that the instance has been properly created, we can simply get
|
# Now that the instance has been properly created, we can simply get
|
||||||
# the method.
|
# the method.
|
||||||
values = values.py__getattribute__(method_name)
|
values = values.py__getattribute__(method_name)
|
||||||
|
if decorates is not None:
|
||||||
|
values = ValueSet(Decoratee(v, decorates) for v in values)
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -97,3 +97,21 @@ def test_builtin_docstring(goto_or_help_or_infer, skip_python2):
|
|||||||
doc = d.docstring()
|
doc = d.docstring()
|
||||||
assert doc.startswith('open(file: Union[')
|
assert doc.startswith('open(file: Union[')
|
||||||
assert 'Open file' in doc
|
assert 'Open file' in doc
|
||||||
|
|
||||||
|
|
||||||
|
def test_docstring_decorator(goto_or_help_or_infer, skip_python2):
|
||||||
|
code = dedent('''
|
||||||
|
import types
|
||||||
|
|
||||||
|
def dec(func):
|
||||||
|
return types.FunctionType()
|
||||||
|
|
||||||
|
@dec
|
||||||
|
def func(a, b):
|
||||||
|
"hello"
|
||||||
|
return
|
||||||
|
func''')
|
||||||
|
d, = goto_or_help_or_infer(code)
|
||||||
|
|
||||||
|
doc = d.docstring()
|
||||||
|
assert doc == 'FunctionType(*args: Any, **kwargs: Any) -> Any\n\nhello'
|
||||||
|
|||||||
Reference in New Issue
Block a user