mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Make sure __wrapped__ works properly when using an Interpreter, fixes #1353
This commit is contained in:
@@ -4,6 +4,7 @@ Used only for REPL Completion.
|
|||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from jedi.parser_utils import get_cached_code_lines
|
from jedi.parser_utils import get_cached_code_lines
|
||||||
|
|
||||||
@@ -131,6 +132,9 @@ def _load_module(evaluator, path):
|
|||||||
|
|
||||||
def _get_object_to_check(python_object):
|
def _get_object_to_check(python_object):
|
||||||
"""Check if inspect.getfile has a chance to find the source."""
|
"""Check if inspect.getfile has a chance to find the source."""
|
||||||
|
if sys.version_info[0] > 2:
|
||||||
|
python_object = inspect.unwrap(python_object)
|
||||||
|
|
||||||
if (inspect.ismodule(python_object) or
|
if (inspect.ismodule(python_object) or
|
||||||
inspect.isclass(python_object) or
|
inspect.isclass(python_object) or
|
||||||
inspect.ismethod(python_object) or
|
inspect.ismethod(python_object) or
|
||||||
|
|||||||
@@ -426,3 +426,16 @@ def test_simple_completions(code, completions):
|
|||||||
|
|
||||||
defs = jedi.Interpreter(code, [locals()]).completions()
|
defs = jedi.Interpreter(code, [locals()]).completions()
|
||||||
assert [d.name for d in defs] == completions
|
assert [d.name for d in defs] == completions
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Python 2 doesn't have lru_cache")
|
||||||
|
def test__wrapped__():
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
|
@lru_cache(maxsize=128)
|
||||||
|
def syslogs_to_df():
|
||||||
|
pass
|
||||||
|
|
||||||
|
c, = jedi.Interpreter('syslogs_to_df', [locals()]).completions()
|
||||||
|
# Apparently the function starts on the line where the decorator starts.
|
||||||
|
assert c.line == syslogs_to_df.__wrapped__.__code__.co_firstlineno + 1
|
||||||
|
|||||||
Reference in New Issue
Block a user