mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-23 05:41:27 +08:00
Try to get some more stub to definitions working and vice versa
This commit is contained in:
@@ -14,7 +14,7 @@ from jedi.evaluate import imports
|
|||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate.imports import ImportName
|
from jedi.evaluate.imports import ImportName
|
||||||
from jedi.evaluate.filters import ParamName
|
from jedi.evaluate.filters import ParamName
|
||||||
from jedi.evaluate.context import FunctionExecutionContext
|
from jedi.evaluate.context import FunctionExecutionContext, MethodContext
|
||||||
from jedi.evaluate.gradual.typeshed import StubOnlyModuleContext
|
from jedi.evaluate.gradual.typeshed import StubOnlyModuleContext
|
||||||
from jedi.api.keywords import KeywordName
|
from jedi.api.keywords import KeywordName
|
||||||
|
|
||||||
@@ -318,7 +318,16 @@ class BaseDefinition(object):
|
|||||||
if self._name.tree_name is None:
|
if self._name.tree_name is None:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
names = self._evaluator.goto(self._name.parent_context, self._name.tree_name)
|
# TODO remove this paragraph, it's ugly and shouldn't be needed
|
||||||
|
inferred = self._name.infer()
|
||||||
|
if not inferred:
|
||||||
|
return None
|
||||||
|
inferred = next(iter(inferred))
|
||||||
|
if isinstance(inferred, MethodContext):
|
||||||
|
c = inferred.class_context
|
||||||
|
else:
|
||||||
|
c = self._name.parent_context
|
||||||
|
names = self._evaluator.goto(c, self._name.tree_name)
|
||||||
return [Definition(self._evaluator, n) for n in names]
|
return [Definition(self._evaluator, n) for n in names]
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ from jedi.evaluate.context.iterable import CompForContext
|
|||||||
from jedi.evaluate.syntax_tree import eval_trailer, eval_expr_stmt, \
|
from jedi.evaluate.syntax_tree import eval_trailer, eval_expr_stmt, \
|
||||||
eval_node, check_tuple_assignments
|
eval_node, check_tuple_assignments
|
||||||
from jedi.evaluate.gradual.stub_context import with_stub_context_if_possible, \
|
from jedi.evaluate.gradual.stub_context import with_stub_context_if_possible, \
|
||||||
stub_to_actual_context_set, goto_with_stubs_if_possible, goto_non_stub
|
stub_to_actual_context_set, goto_with_stubs_if_possible, goto_non_stub, \
|
||||||
|
stubify
|
||||||
|
|
||||||
|
|
||||||
def _execute(context, arguments):
|
def _execute(context, arguments):
|
||||||
@@ -443,6 +444,7 @@ class Evaluator(object):
|
|||||||
cls = FunctionContext
|
cls = FunctionContext
|
||||||
|
|
||||||
func = cls.from_context(parent_context, scope_node)
|
func = cls.from_context(parent_context, scope_node)
|
||||||
|
func = next(iter(stubify(func)))
|
||||||
|
|
||||||
if parent_was_class:
|
if parent_was_class:
|
||||||
func = BoundMethod(
|
func = BoundMethod(
|
||||||
@@ -453,7 +455,10 @@ class Evaluator(object):
|
|||||||
return func.get_function_execution()
|
return func.get_function_execution()
|
||||||
return func
|
return func
|
||||||
elif scope_node.type == 'classdef':
|
elif scope_node.type == 'classdef':
|
||||||
return ClassContext(self, parent_context, scope_node)
|
return next(iter(stubify(
|
||||||
|
parent_context,
|
||||||
|
ClassContext(self, parent_context, scope_node)
|
||||||
|
)))
|
||||||
elif scope_node.type == 'comp_for':
|
elif scope_node.type == 'comp_for':
|
||||||
if node.start_pos >= scope_node.children[-1].start_pos:
|
if node.start_pos >= scope_node.children[-1].start_pos:
|
||||||
return parent_context
|
return parent_context
|
||||||
|
|||||||
@@ -315,12 +315,23 @@ def stub_to_actual_context_set(stub_context):
|
|||||||
|
|
||||||
stub_only_module = stub_context.get_root_context()
|
stub_only_module = stub_context.get_root_context()
|
||||||
assert isinstance(stub_only_module, StubOnlyModuleContext), stub_only_module
|
assert isinstance(stub_only_module, StubOnlyModuleContext), stub_only_module
|
||||||
non_stubs = stub_only_module.non_stub_context_set
|
non_stubs = stub_only_module.get_stub_contexts()
|
||||||
for name in qualified_names:
|
for name in qualified_names:
|
||||||
non_stubs = non_stubs.py__getattribute__(name)
|
non_stubs = non_stubs.py__getattribute__(name)
|
||||||
return non_stubs
|
return non_stubs
|
||||||
|
|
||||||
|
|
||||||
|
def stubify(parent_context, context):
|
||||||
|
if parent_context.is_stub():
|
||||||
|
return ContextSet(
|
||||||
|
c.stub_context
|
||||||
|
for c in stub_to_actual_context_set(context)
|
||||||
|
if c.stub_context is not None
|
||||||
|
) or ContextSet([context])
|
||||||
|
else:
|
||||||
|
return with_stub_context_if_possible(context)
|
||||||
|
|
||||||
|
|
||||||
class CompiledStubName(NameWrapper):
|
class CompiledStubName(NameWrapper):
|
||||||
def __init__(self, parent_context, compiled_name, stub_name):
|
def __init__(self, parent_context, compiled_name, stub_name):
|
||||||
super(CompiledStubName, self).__init__(stub_name)
|
super(CompiledStubName, self).__init__(stub_name)
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ def _assert_is_same(d1, d2):
|
|||||||
'code', [
|
'code', [
|
||||||
'import os; os.walk',
|
'import os; os.walk',
|
||||||
'from collections import Counter; Counter',
|
'from collections import Counter; Counter',
|
||||||
#'from collections import Counter; Counter.most_common',
|
'from collections import Counter; Counter.most_common',
|
||||||
])
|
])
|
||||||
def test_goto_stubs_on_itself(Script, code, type_):
|
def test_goto_stubs_on_itself(Script, code, type_):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user