mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-21 23:28:27 +08:00
context -> value
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user