1
0
forked from VimPlug/jedi

Fix a python 2 dynamic issue

This commit is contained in:
Dave Halter
2019-08-21 01:13:19 +02:00
parent 4cbe2898c0
commit 84f6d95fde
3 changed files with 14 additions and 14 deletions

View File

@@ -179,34 +179,34 @@ def _get_possible_nodes(module_value, func_string_name):
def _check_name_for_execution(inference_state, context, compare_node, name, trailer): def _check_name_for_execution(inference_state, context, compare_node, name, trailer):
from jedi.inference.value.function import FunctionExecutionContext from jedi.inference.value.function import FunctionExecutionContext
def create_func_excs(): def create_func_excs(value):
arglist = trailer.children[1] arglist = trailer.children[1]
if arglist == ')': if arglist == ')':
arglist = None arglist = None
args = TreeArguments(inference_state, context, arglist, trailer) args = TreeArguments(inference_state, context, arglist, trailer)
if value_node.type == 'classdef': if value.tree_node.type == 'classdef':
created_instance = instance.TreeInstance( created_instance = instance.TreeInstance(
inference_state, inference_state,
v.parent_context, value.parent_context,
v, value,
args args
) )
for execution in created_instance.create_init_executions(): for execution in created_instance.create_init_executions():
yield execution yield execution
else: else:
yield v.get_function_execution(args) yield value.get_function_execution(args)
for v in inference_state.goto_definitions(context, name): for value in inference_state.goto_definitions(context, name):
value_node = v.tree_node value_node = value.tree_node
if compare_node == value_node: if compare_node == value_node:
for func_execution in create_func_excs(): for func_execution in create_func_excs(value):
yield func_execution yield func_execution
elif isinstance(v.parent_context, FunctionExecutionContext) and \ elif isinstance(value.parent_context, FunctionExecutionContext) and \
compare_node.type == 'funcdef': compare_node.type == 'funcdef':
# Here we're trying to find decorators by checking the first # Here we're trying to find decorators by checking the first
# parameter. It's not very generic though. Should find a better # parameter. It's not very generic though. Should find a better
# solution that also applies to nested decorators. # solution that also applies to nested decorators.
params, _ = v.parent_context.get_executed_params_and_issues() params, _ = value.parent_context.get_executed_params_and_issues()
if len(params) != 1: if len(params) != 1:
continue continue
values = params[0].infer() values = params[0].infer()
@@ -214,10 +214,10 @@ def _check_name_for_execution(inference_state, context, compare_node, name, trai
if nodes == [compare_node]: if nodes == [compare_node]:
# Found a decorator. # Found a decorator.
module_context = context.get_root_context() module_context = context.get_root_context()
execution_context = next(create_func_excs()) execution_context = next(create_func_excs(value))
for name, trailer in _get_possible_nodes(module_context, params[0].string_name): for name, trailer in _get_possible_nodes(module_context, params[0].string_name):
if value_node.start_pos < name.start_pos < value_node.end_pos: if value_node.start_pos < name.start_pos < value_node.end_pos:
random_value = inference_state.create_context(execution_context, name) random_value = execution_context.create_context(name)
iterator = _check_name_for_execution( iterator = _check_name_for_execution(
inference_state, inference_state,
random_value, random_value,

View File

@@ -108,7 +108,7 @@ def import_module_decorator(func):
python_parent, = inference_state.import_module(('os',), prefer_stubs=False) python_parent, = inference_state.import_module(('os',), prefer_stubs=False)
python_value_set = ValueSet.from_sets( python_value_set = ValueSet.from_sets(
func(inference_state, (n,), None, sys_path,) func(inference_state, (n,), None, sys_path,)
for n in ['posixpath', 'ntpath', 'macpath', 'os2emxpath'] for n in [u'posixpath', u'ntpath', u'macpath', u'os2emxpath']
) )
else: else:
python_value_set = ValueSet.from_sets( python_value_set = ValueSet.from_sets(

View File

@@ -386,7 +386,7 @@ def test_import(names):
n = nms[1].goto_assignments()[0] n = nms[1].goto_assignments()[0]
# This is very special, normally the name doesn't chance, but since # This is very special, normally the name doesn't chance, but since
# os.path is a sys.modules hack, it does. # os.path is a sys.modules hack, it does.
assert n.name in ('ntpath', 'posixpath', 'os2emxpath') assert n.name in ('macpath', 'ntpath', 'posixpath', 'os2emxpath')
assert n.type == 'module' assert n.type == 'module'