Fix stub conversion for Decoratee, so docstrings work, see #117

This commit is contained in:
Dave Halter
2020-03-21 17:23:27 +01:00
parent 88c13639bc
commit a2f4d1bbe7
2 changed files with 25 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ from jedi.inference.base_value import ValueSet, \
from jedi.inference.utils import to_list
from jedi.inference.gradual.stub_value import StubModuleValue
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):
@@ -11,6 +12,10 @@ def _stub_to_python_value_set(stub_value, ignore_compiled=False):
if not stub_module_context.is_stub():
return ValueSet([stub_value])
decorates = None
if isinstance(stub_value, Decoratee):
decorates = stub_value._original_value
was_instance = stub_value.is_instance()
if was_instance:
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
# the method.
values = values.py__getattribute__(method_name)
if decorates is not None:
values = ValueSet(Decoratee(v, decorates) for v in values)
return values

View File

@@ -97,3 +97,21 @@ def test_builtin_docstring(goto_or_help_or_infer, skip_python2):
doc = d.docstring()
assert doc.startswith('open(file: Union[')
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'