mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Fix create_context for param default arguments/annotations
This commit is contained in:
@@ -499,9 +499,8 @@ def names(source=None, path=None, encoding='utf-8', all_scopes=False,
|
|||||||
cls = ParamName
|
cls = ParamName
|
||||||
else:
|
else:
|
||||||
cls = TreeNameDefinition
|
cls = TreeNameDefinition
|
||||||
is_module = name.parent.type == 'file_input'
|
|
||||||
return cls(
|
return cls(
|
||||||
module_context.create_context(name if is_module else name.parent),
|
module_context.create_context(name),
|
||||||
name
|
name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -461,11 +461,13 @@ class Evaluator(object):
|
|||||||
if node_is_context and parser_utils.is_scope(node):
|
if node_is_context and parser_utils.is_scope(node):
|
||||||
scope_node = node
|
scope_node = node
|
||||||
else:
|
else:
|
||||||
if node.parent.type in ('funcdef', 'classdef') and node.parent.name == node:
|
|
||||||
# When we're on class/function names/leafs that define the
|
|
||||||
# object itself and not its contents.
|
|
||||||
node = node.parent
|
|
||||||
scope_node = parent_scope(node)
|
scope_node = parent_scope(node)
|
||||||
|
if scope_node.type in ('funcdef', 'classdef'):
|
||||||
|
colon = scope_node.children[scope_node.children.index(':')]
|
||||||
|
if node.start_pos < colon.start_pos:
|
||||||
|
parent = node.parent
|
||||||
|
if not (parent.type == 'param' and parent.name == node):
|
||||||
|
scope_node = parent_scope(scope_node)
|
||||||
return from_scope_node(scope_node, is_nested=True, node_is_object=node_is_object)
|
return from_scope_node(scope_node, is_nested=True, node_is_object=node_is_object)
|
||||||
|
|
||||||
def parse_and_get_code(self, code=None, path=None, encoding='utf-8',
|
def parse_and_get_code(self, code=None, path=None, encoding='utf-8',
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ def search_params(evaluator, execution_context, funcdef):
|
|||||||
function_execution.get_executed_params_and_issues()[0]
|
function_execution.get_executed_params_and_issues()[0]
|
||||||
for function_execution in function_executions
|
for function_execution in function_executions
|
||||||
))
|
))
|
||||||
params = [DynamicExecutedParams(evaluator, executed_params) for executed_params in zipped_params]
|
params = [DynamicExecutedParams(evaluator, executed_params)
|
||||||
|
for executed_params in zipped_params]
|
||||||
# Evaluate the ExecutedParams to types.
|
# Evaluate the ExecutedParams to types.
|
||||||
else:
|
else:
|
||||||
return create_default_params(execution_context, funcdef)
|
return create_default_params(execution_context, funcdef)
|
||||||
|
|||||||
@@ -122,6 +122,15 @@ A(3).test(2.0)
|
|||||||
A(3).test2()
|
A(3).test2()
|
||||||
|
|
||||||
|
|
||||||
|
def from_class(x):
|
||||||
|
#?
|
||||||
|
x
|
||||||
|
|
||||||
|
from UNDEFINED import from_class
|
||||||
|
|
||||||
|
class Foo(from_class(1),):
|
||||||
|
pass
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# comprehensions
|
# comprehensions
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user