From 84f6d95fdea49b44b460a2fb0ca1af675e5e8f68 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 21 Aug 2019 01:13:19 +0200 Subject: [PATCH] Fix a python 2 dynamic issue --- jedi/inference/dynamic.py | 24 ++++++++++++------------ jedi/inference/gradual/typeshed.py | 2 +- test/test_api/test_classes.py | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/jedi/inference/dynamic.py b/jedi/inference/dynamic.py index 5d864338..a81fd3da 100644 --- a/jedi/inference/dynamic.py +++ b/jedi/inference/dynamic.py @@ -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): from jedi.inference.value.function import FunctionExecutionContext - def create_func_excs(): + def create_func_excs(value): arglist = trailer.children[1] if arglist == ')': arglist = None args = TreeArguments(inference_state, context, arglist, trailer) - if value_node.type == 'classdef': + if value.tree_node.type == 'classdef': created_instance = instance.TreeInstance( inference_state, - v.parent_context, - v, + value.parent_context, + value, args ) for execution in created_instance.create_init_executions(): yield execution else: - yield v.get_function_execution(args) + yield value.get_function_execution(args) - for v in inference_state.goto_definitions(context, name): - value_node = v.tree_node + for value in inference_state.goto_definitions(context, name): + value_node = value.tree_node if compare_node == value_node: - for func_execution in create_func_excs(): + for func_execution in create_func_excs(value): yield func_execution - elif isinstance(v.parent_context, FunctionExecutionContext) and \ + elif isinstance(value.parent_context, FunctionExecutionContext) and \ compare_node.type == 'funcdef': # Here we're trying to find decorators by checking the first # parameter. It's not very generic though. Should find a better # 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: continue values = params[0].infer() @@ -214,10 +214,10 @@ def _check_name_for_execution(inference_state, context, compare_node, name, trai if nodes == [compare_node]: # Found a decorator. 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): 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( inference_state, random_value, diff --git a/jedi/inference/gradual/typeshed.py b/jedi/inference/gradual/typeshed.py index 1dc9d511..f172c94f 100644 --- a/jedi/inference/gradual/typeshed.py +++ b/jedi/inference/gradual/typeshed.py @@ -108,7 +108,7 @@ def import_module_decorator(func): python_parent, = inference_state.import_module(('os',), prefer_stubs=False) python_value_set = ValueSet.from_sets( 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: python_value_set = ValueSet.from_sets( diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index 31084f39..ee917ecf 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -386,7 +386,7 @@ def test_import(names): n = nms[1].goto_assignments()[0] # This is very special, normally the name doesn't chance, but since # 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'