mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
Working with CompiledObject in stubs is now possible
This commit is contained in:
@@ -10,6 +10,7 @@ from jedi.evaluate.base_context import ContextSet, iterator_to_context_set
|
|||||||
from jedi.evaluate.filters import AbstractTreeName, ParserTreeFilter, \
|
from jedi.evaluate.filters import AbstractTreeName, ParserTreeFilter, \
|
||||||
TreeNameDefinition
|
TreeNameDefinition
|
||||||
from jedi.evaluate.context import ModuleContext, FunctionContext, ClassContext
|
from jedi.evaluate.context import ModuleContext, FunctionContext, ClassContext
|
||||||
|
from jedi.evaluate.compiled import CompiledObject
|
||||||
from jedi.evaluate.syntax_tree import tree_name_to_contexts
|
from jedi.evaluate.syntax_tree import tree_name_to_contexts
|
||||||
from jedi.evaluate.utils import to_list
|
from jedi.evaluate.utils import to_list
|
||||||
|
|
||||||
@@ -127,6 +128,11 @@ class TypeshedPlugin(BasePlugin):
|
|||||||
else parent_module_context,
|
else parent_module_context,
|
||||||
sys_path
|
sys_path
|
||||||
)
|
)
|
||||||
|
# Don't use CompiledObjects, they are just annoying and don't
|
||||||
|
# really help with anything. Just use the stub files instead.
|
||||||
|
context_set = ContextSet.from_iterable(
|
||||||
|
c for c in context_set if not isinstance(c, CompiledObject)
|
||||||
|
)
|
||||||
import_name = import_names[-1]
|
import_name = import_names[-1]
|
||||||
map_ = None
|
map_ = None
|
||||||
if len(import_names) == 1 and import_name != 'typing':
|
if len(import_names) == 1 and import_name != 'typing':
|
||||||
|
|||||||
@@ -79,3 +79,10 @@ def test_method(Script):
|
|||||||
context = def_._name._context
|
context = def_._name._context
|
||||||
assert isinstance(context, CompiledInstance)
|
assert isinstance(context, CompiledInstance)
|
||||||
assert context.class_context.py__name__() == 'str'
|
assert context.class_context.py__name__() == 'str'
|
||||||
|
|
||||||
|
|
||||||
|
def test_math(Script):
|
||||||
|
def_, = Script('import math; math.acos()').goto_definitions()
|
||||||
|
assert def_.name == 'float'
|
||||||
|
context = def_._name._context
|
||||||
|
assert context
|
||||||
|
|||||||
Reference in New Issue
Block a user