mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-06 03:07:40 +08:00
context -> value
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
Special cases of completions (typically special positions that caused issues
|
||||
with context parsing.
|
||||
with value parsing.
|
||||
"""
|
||||
|
||||
def pass_decorator(func):
|
||||
|
||||
@@ -36,7 +36,7 @@ definition = 0
|
||||
str(def
|
||||
|
||||
|
||||
# It might be hard to determine the context
|
||||
# It might be hard to determine the value
|
||||
class Foo(object):
|
||||
@property
|
||||
#? ['str']
|
||||
|
||||
18
test/run.py
18
test/run.py
@@ -126,7 +126,7 @@ from jedi.api.classes import Definition
|
||||
from jedi.api.completion import get_user_scope
|
||||
from jedi import parser_utils
|
||||
from jedi.api.environment import get_default_environment, get_system_environment
|
||||
from jedi.inference.gradual.conversion import convert_contexts
|
||||
from jedi.inference.gradual.conversion import convert_values
|
||||
|
||||
|
||||
TEST_COMPLETIONS = 0
|
||||
@@ -225,14 +225,14 @@ class IntegrationTestCase(object):
|
||||
parser = grammar36.parse(string, start_symbol='eval_input', error_recovery=False)
|
||||
parser_utils.move(parser.get_root_node(), self.line_nr)
|
||||
element = parser.get_root_node()
|
||||
module_context = script._get_module()
|
||||
# The context shouldn't matter for the test results.
|
||||
user_context = get_user_scope(module_context, (self.line_nr, 0))
|
||||
if user_context.api_type == 'function':
|
||||
user_context = user_context.get_function_execution()
|
||||
element.parent = user_context.tree_node
|
||||
results = convert_contexts(
|
||||
infer_state.infer_element(user_context, element),
|
||||
module_value = script._get_module()
|
||||
# The value shouldn't matter for the test results.
|
||||
user_value = get_user_scope(module_value, (self.line_nr, 0))
|
||||
if user_value.api_type == 'function':
|
||||
user_value = user_value.get_function_execution()
|
||||
element.parent = user_value.tree_node
|
||||
results = convert_values(
|
||||
infer_state.infer_element(user_value, element),
|
||||
)
|
||||
if not results:
|
||||
raise Exception('Could not resolve %s on line %s'
|
||||
|
||||
@@ -398,7 +398,7 @@ def test_import_alias(names):
|
||||
n = nms[0].goto_assignments()[0]
|
||||
assert n.name == 'json'
|
||||
assert n.type == 'module'
|
||||
assert n._name._context.tree_node.type == 'file_input'
|
||||
assert n._name._value.tree_node.type == 'file_input'
|
||||
|
||||
assert nms[1].name == 'foo'
|
||||
assert nms[1].type == 'module'
|
||||
@@ -407,7 +407,7 @@ def test_import_alias(names):
|
||||
assert len(ass) == 1
|
||||
assert ass[0].name == 'json'
|
||||
assert ass[0].type == 'module'
|
||||
assert ass[0]._name._context.tree_node.type == 'file_input'
|
||||
assert ass[0]._name._value.tree_node.type == 'file_input'
|
||||
|
||||
|
||||
def test_added_equals_to_params(Script):
|
||||
|
||||
@@ -34,7 +34,7 @@ def test_in_empty_space(Script):
|
||||
assert def_.name == 'X'
|
||||
|
||||
|
||||
def test_indent_context(Script):
|
||||
def test_indent_value(Script):
|
||||
"""
|
||||
If an INDENT is the next supposed token, we should still be able to
|
||||
complete.
|
||||
@@ -44,7 +44,7 @@ def test_indent_context(Script):
|
||||
assert comp.name == 'isinstance'
|
||||
|
||||
|
||||
def test_keyword_context(Script):
|
||||
def test_keyword_value(Script):
|
||||
def get_names(*args, **kwargs):
|
||||
return [d.name for d in Script(*args, **kwargs).completions()]
|
||||
|
||||
@@ -101,8 +101,8 @@ def test_fake_subnodes(Script):
|
||||
for i in range(2):
|
||||
completions = Script('').completions()
|
||||
c = get_str_completion(completions)
|
||||
str_context, = c._name.infer()
|
||||
n = len(str_context.tree_node.children[-1].children)
|
||||
str_value, = c._name.infer()
|
||||
n = len(str_value.tree_node.children[-1].children)
|
||||
if i == 0:
|
||||
limit = n
|
||||
else:
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
|
||||
import jedi
|
||||
from jedi._compatibility import is_py3, py_version
|
||||
from jedi.inference.compiled import mixed, context
|
||||
from jedi.inference.compiled import mixed, value
|
||||
from importlib import import_module
|
||||
|
||||
if py_version > 30:
|
||||
@@ -101,8 +101,8 @@ def test_side_effect_completion():
|
||||
side_effect = get_completion('SideEffectContainer', _GlobalNameSpace.__dict__)
|
||||
|
||||
# It's a class that contains MixedObject.
|
||||
context, = side_effect._name.infer()
|
||||
assert isinstance(context, mixed.MixedObject)
|
||||
value, = side_effect._name.infer()
|
||||
assert isinstance(value, mixed.MixedObject)
|
||||
foo = get_completion('SideEffectContainer.foo', _GlobalNameSpace.__dict__)
|
||||
assert foo.name == 'foo'
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ from ..helpers import cwd_at
|
||||
|
||||
|
||||
def check_module_test(Script, code):
|
||||
module_context = Script(code)._get_module()
|
||||
return check_sys_path_modifications(module_context)
|
||||
module_value = Script(code)._get_module()
|
||||
return check_sys_path_modifications(module_value)
|
||||
|
||||
|
||||
@cwd_at('test/examples/buildout_project/src/proj_name')
|
||||
|
||||
@@ -8,7 +8,7 @@ import pytest
|
||||
|
||||
from jedi.inference import compiled
|
||||
from jedi.inference.compiled.access import DirectObjectAccess
|
||||
from jedi.inference.gradual.conversion import _stub_to_python_context_set
|
||||
from jedi.inference.gradual.conversion import _stub_to_python_value_set
|
||||
|
||||
|
||||
def test_simple(infer_state, environment):
|
||||
@@ -34,7 +34,7 @@ def test_next_docstr(infer_state):
|
||||
next_ = compiled.builtin_from_name(infer_state, u'next')
|
||||
assert next_.tree_node is not None
|
||||
assert next_.py__doc__() == '' # It's a stub
|
||||
for non_stub in _stub_to_python_context_set(next_):
|
||||
for non_stub in _stub_to_python_value_set(next_):
|
||||
assert non_stub.py__doc__() == next.__doc__
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ def test_parse_function_doc_illegal_docstr():
|
||||
|
||||
doesn't have a closing bracket.
|
||||
"""
|
||||
assert ('', '') == compiled.context._parse_function_doc(docstr)
|
||||
assert ('', '') == compiled.value._parse_function_doc(docstr)
|
||||
|
||||
|
||||
def test_doc(infer_state):
|
||||
@@ -122,7 +122,7 @@ def _return_int():
|
||||
('ret_int', '_return_int', 'test.test_inference.test_compiled'),
|
||||
]
|
||||
)
|
||||
def test_parent_context(same_process_infer_state, attribute, expected_name, expected_parent):
|
||||
def test_parent_value(same_process_infer_state, attribute, expected_name, expected_parent):
|
||||
import decimal
|
||||
|
||||
class C:
|
||||
@@ -140,11 +140,11 @@ def test_parent_context(same_process_infer_state, attribute, expected_name, expe
|
||||
)
|
||||
x, = o.py__getattribute__(attribute)
|
||||
assert x.py__name__() == expected_name
|
||||
module_name = x.parent_context.py__name__()
|
||||
module_name = x.parent_value.py__name__()
|
||||
if module_name == '__builtin__':
|
||||
module_name = 'builtins' # Python 2
|
||||
assert module_name == expected_parent
|
||||
assert x.parent_context.parent_context is None
|
||||
assert x.parent_value.parent_value is None
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
|
||||
|
||||
@@ -13,9 +13,9 @@ def test_module_attributes(Script):
|
||||
def test_module__file__(Script, environment):
|
||||
assert not Script('__file__').goto_definitions()
|
||||
def_, = Script('__file__', path='example.py').goto_definitions()
|
||||
value = force_unicode(def_._name._context.get_safe_value())
|
||||
value = force_unicode(def_._name._value.get_safe_value())
|
||||
assert value.endswith('example.py')
|
||||
|
||||
def_, = Script('import antigravity; antigravity.__file__').goto_definitions()
|
||||
value = force_unicode(def_._name._context.get_safe_value())
|
||||
value = force_unicode(def_._name._value.get_safe_value())
|
||||
assert value.endswith('.py')
|
||||
|
||||
@@ -3,8 +3,8 @@ import os
|
||||
import pytest
|
||||
from parso.utils import PythonVersionInfo
|
||||
|
||||
from jedi.inference.gradual import typeshed, stub_context
|
||||
from jedi.inference.context import TreeInstance, BoundMethod, FunctionContext, \
|
||||
from jedi.inference.gradual import typeshed, stub_value
|
||||
from jedi.inference.value import TreeInstance, BoundMethod, FunctionContext, \
|
||||
MethodContext, ClassContext
|
||||
|
||||
TYPESHED_PYTHON3 = os.path.join(typeshed.TYPESHED_PATH, 'stdlib', '3')
|
||||
@@ -47,15 +47,15 @@ def test_get_stub_files():
|
||||
def test_function(Script, environment):
|
||||
code = 'import threading; threading.current_thread'
|
||||
def_, = Script(code).goto_definitions()
|
||||
context = def_._name._context
|
||||
assert isinstance(context, FunctionContext), context
|
||||
value = def_._name._value
|
||||
assert isinstance(value, FunctionContext), value
|
||||
|
||||
def_, = Script(code + '()').goto_definitions()
|
||||
context = def_._name._context
|
||||
assert isinstance(context, TreeInstance)
|
||||
value = def_._name._value
|
||||
assert isinstance(value, TreeInstance)
|
||||
|
||||
def_, = Script('import threading; threading.Thread').goto_definitions()
|
||||
assert isinstance(def_._name._context, ClassContext), def_
|
||||
assert isinstance(def_._name._value, ClassContext), def_
|
||||
|
||||
|
||||
def test_keywords_variable(Script):
|
||||
@@ -69,33 +69,33 @@ def test_keywords_variable(Script):
|
||||
|
||||
def test_class(Script):
|
||||
def_, = Script('import threading; threading.Thread').goto_definitions()
|
||||
context = def_._name._context
|
||||
assert isinstance(context, ClassContext), context
|
||||
value = def_._name._value
|
||||
assert isinstance(value, ClassContext), value
|
||||
|
||||
|
||||
def test_instance(Script):
|
||||
def_, = Script('import threading; threading.Thread()').goto_definitions()
|
||||
context = def_._name._context
|
||||
assert isinstance(context, TreeInstance)
|
||||
value = def_._name._value
|
||||
assert isinstance(value, TreeInstance)
|
||||
|
||||
|
||||
def test_class_function(Script):
|
||||
def_, = Script('import threading; threading.Thread.getName').goto_definitions()
|
||||
context = def_._name._context
|
||||
assert isinstance(context, MethodContext), context
|
||||
value = def_._name._value
|
||||
assert isinstance(value, MethodContext), value
|
||||
|
||||
|
||||
def test_method(Script):
|
||||
code = 'import threading; threading.Thread().getName'
|
||||
def_, = Script(code).goto_definitions()
|
||||
context = def_._name._context
|
||||
assert isinstance(context, BoundMethod), context
|
||||
assert isinstance(context._wrapped_context, MethodContext), context
|
||||
value = def_._name._value
|
||||
assert isinstance(value, BoundMethod), value
|
||||
assert isinstance(value._wrapped_value, MethodContext), value
|
||||
|
||||
def_, = Script(code + '()').goto_definitions()
|
||||
context = def_._name._context
|
||||
assert isinstance(context, TreeInstance)
|
||||
assert context.class_context.py__name__() == 'str'
|
||||
value = def_._name._value
|
||||
assert isinstance(value, TreeInstance)
|
||||
assert value.class_value.py__name__() == 'str'
|
||||
|
||||
|
||||
def test_sys_exc_info(Script):
|
||||
@@ -125,7 +125,7 @@ def test_sys_getwindowsversion(Script, environment):
|
||||
def test_sys_hexversion(Script):
|
||||
script = Script('import sys; sys.hexversion')
|
||||
def_, = script.completions()
|
||||
assert isinstance(def_._name, stub_context._StubName), def_._name
|
||||
assert isinstance(def_._name, stub_value._StubName), def_._name
|
||||
assert typeshed.TYPESHED_PATH in def_.module_path
|
||||
def_, = script.goto_definitions()
|
||||
assert def_.name == 'int'
|
||||
@@ -134,8 +134,8 @@ def test_sys_hexversion(Script):
|
||||
def test_math(Script):
|
||||
def_, = Script('import math; math.acos()').goto_definitions()
|
||||
assert def_.name == 'float'
|
||||
context = def_._name._context
|
||||
assert context
|
||||
value = def_._name._value
|
||||
assert value
|
||||
|
||||
|
||||
def test_type_var(Script):
|
||||
|
||||
@@ -12,7 +12,7 @@ from jedi._compatibility import find_module_py33, find_module
|
||||
from jedi.inference import compiled
|
||||
from jedi.inference import imports
|
||||
from jedi.api.project import Project
|
||||
from jedi.inference.gradual.conversion import _stub_to_python_context_set
|
||||
from jedi.inference.gradual.conversion import _stub_to_python_value_set
|
||||
from ..helpers import cwd_at, get_example_dir, test_dir, root_dir
|
||||
|
||||
THIS_DIR = os.path.dirname(__file__)
|
||||
@@ -88,12 +88,12 @@ def test_correct_zip_package_behavior(Script, infer_state, environment, code,
|
||||
file, package, path, skip_python2):
|
||||
sys_path = environment.get_sys_path() + [pkg_zip_path]
|
||||
pkg, = Script(code, sys_path=sys_path).goto_definitions()
|
||||
context, = pkg._name.infer()
|
||||
assert context.py__file__() == os.path.join(pkg_zip_path, 'pkg', file)
|
||||
assert '.'.join(context.py__package__()) == package
|
||||
assert context.is_package is (path is not None)
|
||||
value, = pkg._name.infer()
|
||||
assert value.py__file__() == os.path.join(pkg_zip_path, 'pkg', file)
|
||||
assert '.'.join(value.py__package__()) == package
|
||||
assert value.is_package is (path is not None)
|
||||
if path is not None:
|
||||
assert context.py__path__() == [os.path.join(pkg_zip_path, path)]
|
||||
assert value.py__path__() == [os.path.join(pkg_zip_path, path)]
|
||||
|
||||
|
||||
def test_find_module_not_package_zipped(Script, infer_state, environment):
|
||||
@@ -156,8 +156,8 @@ def test_not_importable_file(Script):
|
||||
def test_import_unique(Script):
|
||||
src = "import os; os.path"
|
||||
defs = Script(src, path='example.py').goto_definitions()
|
||||
parent_contexts = [d._name._context for d in defs]
|
||||
assert len(parent_contexts) == len(set(parent_contexts))
|
||||
parent_values = [d._name._value for d in defs]
|
||||
assert len(parent_values) == len(set(parent_values))
|
||||
|
||||
|
||||
def test_cache_works_with_sys_path_param(Script, tmpdir):
|
||||
@@ -300,8 +300,8 @@ def test_compiled_import_none(monkeypatch, Script):
|
||||
monkeypatch.setattr(compiled, 'load_module', lambda *args, **kwargs: None)
|
||||
def_, = script.goto_definitions()
|
||||
assert def_.type == 'module'
|
||||
context, = def_._name.infer()
|
||||
assert not _stub_to_python_context_set(context)
|
||||
value, = def_._name.infer()
|
||||
assert not _stub_to_python_value_set(value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import pytest
|
||||
from jedi.inference.context import TreeInstance
|
||||
from jedi.inference.value import TreeInstance
|
||||
|
||||
|
||||
def _infer_literal(Script, code, is_fstring=False):
|
||||
def_, = Script(code).goto_definitions()
|
||||
if is_fstring:
|
||||
assert def_.name == 'str'
|
||||
assert isinstance(def_._name._context, TreeInstance)
|
||||
assert isinstance(def_._name._value, TreeInstance)
|
||||
return ''
|
||||
else:
|
||||
return def_._name._context.get_safe_value()
|
||||
return def_._name._value.get_safe_value()
|
||||
|
||||
|
||||
def test_f_strings(Script, environment):
|
||||
|
||||
@@ -3,7 +3,7 @@ from textwrap import dedent
|
||||
|
||||
def get_definition_and_infer_state(Script, source):
|
||||
first, = Script(dedent(source)).goto_definitions()
|
||||
return first._name._context, first._infer_state
|
||||
return first._name._value, first._infer_state
|
||||
|
||||
|
||||
def test_function_execution(Script):
|
||||
|
||||
@@ -4,7 +4,7 @@ import re
|
||||
|
||||
import pytest
|
||||
|
||||
from jedi.inference.gradual.conversion import _stub_to_python_context_set
|
||||
from jedi.inference.gradual.conversion import _stub_to_python_value_set
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -30,8 +30,8 @@ def test_compiled_signature(Script, environment, code, sig, names, op, version):
|
||||
return # The test right next to it should take over.
|
||||
|
||||
d, = Script(code).goto_definitions()
|
||||
context, = d._name.infer()
|
||||
compiled, = _stub_to_python_context_set(context)
|
||||
value, = d._name.infer()
|
||||
compiled, = _stub_to_python_value_set(value)
|
||||
signature, = compiled.get_signatures()
|
||||
assert signature.to_string() == sig
|
||||
assert [n.string_name for n in signature.get_param_names()] == names
|
||||
|
||||
@@ -83,7 +83,7 @@ def test_add_to_end(Script):
|
||||
|
||||
def test_tokenizer_with_string_literal_backslash(Script):
|
||||
c = Script("statement = u'foo\\\n'; statement").goto_definitions()
|
||||
assert c[0]._name._context.get_safe_value() == 'foo'
|
||||
assert c[0]._name._value.get_safe_value() == 'foo'
|
||||
|
||||
|
||||
def test_ellipsis_without_getitem(Script, environment):
|
||||
|
||||
@@ -14,8 +14,8 @@ def auto_import_json(monkeypatch):
|
||||
def test_base_auto_import_modules(auto_import_json, Script):
|
||||
loads, = Script('import json; json.loads').goto_definitions()
|
||||
assert isinstance(loads._name, ContextName)
|
||||
context, = loads._name.infer()
|
||||
assert isinstance(context.parent_context, StubModuleContext)
|
||||
value, = loads._name.infer()
|
||||
assert isinstance(value.parent_value, StubModuleContext)
|
||||
|
||||
|
||||
def test_auto_import_modules_imports(auto_import_json, Script):
|
||||
|
||||
Reference in New Issue
Block a user