mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Ensure *args, **kwargs lookthrough works at module scope too
This means that passthrough signatures will be found for top level functions, which is useful both where they're wrappered by `functools.wraps` or not. Fixes https://github.com/davidhalter/jedi/issues/1791.
This commit is contained in:
@@ -22,7 +22,15 @@ def _iter_nodes_for_param(param_name):
|
|||||||
from jedi.inference.arguments import TreeArguments
|
from jedi.inference.arguments import TreeArguments
|
||||||
|
|
||||||
execution_context = param_name.parent_context
|
execution_context = param_name.parent_context
|
||||||
function_node = execution_context.tree_node
|
# Walk up the parso tree to get the FunctionNode we want. We use the parso
|
||||||
|
# tree rather than going via the execution context so that we're agnostic of
|
||||||
|
# the specific scope we're evaluating within (i.e: module or function,
|
||||||
|
# etc.).
|
||||||
|
# - .tree_name is a Name
|
||||||
|
# - .parent is a Param
|
||||||
|
# - .parent is a PythonNode(parameters)
|
||||||
|
# - .parent is the FunctionNode we want.
|
||||||
|
function_node = param_name.tree_name.parent.parent.parent
|
||||||
module_node = function_node.get_root_node()
|
module_node = function_node.get_root_node()
|
||||||
start = function_node.children[-1].start_pos
|
start = function_node.children[-1].start_pos
|
||||||
end = function_node.children[-1].end_pos
|
end = function_node.children[-1].end_pos
|
||||||
|
|||||||
@@ -292,6 +292,26 @@ def test_pow_signature(Script, environment):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
x(f)('''), 'f()'],
|
x(f)('''), 'f()'],
|
||||||
|
[dedent('''
|
||||||
|
# identifier:C
|
||||||
|
import functools
|
||||||
|
def f(x: int, y: float):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@functools.wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
|
wrapper('''), 'f(x: int, y: float)'],
|
||||||
|
[dedent('''
|
||||||
|
# identifier:D
|
||||||
|
def f(x: int, y: float):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
|
wrapper('''), 'wrapper(x: int, y: float)'],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_wraps_signature(Script, code, signature):
|
def test_wraps_signature(Script, code, signature):
|
||||||
|
|||||||
Reference in New Issue
Block a user