mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Change some names from actual -> python
This commit is contained in:
@@ -60,7 +60,7 @@ def try_stubs_to_actual_context_set(stub_contexts, prefer_stub_to_compiled=False
|
|||||||
|
|
||||||
|
|
||||||
@to_list
|
@to_list
|
||||||
def try_stub_to_actual_names(names, prefer_stub_to_compiled=False):
|
def _try_stub_to_python_names(names, prefer_stub_to_compiled=False):
|
||||||
for name in names:
|
for name in names:
|
||||||
module = name.get_root_context()
|
module = name.get_root_context()
|
||||||
if not module.is_stub():
|
if not module.is_stub():
|
||||||
@@ -98,14 +98,14 @@ def _load_stub_module(module):
|
|||||||
return _try_to_load_stub_cached(
|
return _try_to_load_stub_cached(
|
||||||
module.evaluator,
|
module.evaluator,
|
||||||
import_names=module.string_names,
|
import_names=module.string_names,
|
||||||
actual_context_set=ContextSet([module]),
|
python_context_set=ContextSet([module]),
|
||||||
parent_module_context=None,
|
parent_module_context=None,
|
||||||
sys_path=module.evaluator.get_sys_path(),
|
sys_path=module.evaluator.get_sys_path(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@to_list
|
@to_list
|
||||||
def actual_to_stub_names(names, fallback_to_actual=False):
|
def _python_to_stub_names(names, fallback_to_python=False):
|
||||||
for name in names:
|
for name in names:
|
||||||
module = name.get_root_context()
|
module = name.get_root_context()
|
||||||
if module.is_stub():
|
if module.is_stub():
|
||||||
@@ -130,7 +130,7 @@ def actual_to_stub_names(names, fallback_to_actual=False):
|
|||||||
for c in stubs:
|
for c in stubs:
|
||||||
yield c.name
|
yield c.name
|
||||||
continue
|
continue
|
||||||
if fallback_to_actual:
|
if fallback_to_python:
|
||||||
# This is the part where if we haven't found anything, just return
|
# This is the part where if we haven't found anything, just return
|
||||||
# the stub name.
|
# the stub name.
|
||||||
yield name
|
yield name
|
||||||
@@ -139,9 +139,9 @@ def actual_to_stub_names(names, fallback_to_actual=False):
|
|||||||
def convert_names(names, only_stubs, prefer_stubs):
|
def convert_names(names, only_stubs, prefer_stubs):
|
||||||
with debug.increase_indent_cm('convert names'):
|
with debug.increase_indent_cm('convert names'):
|
||||||
if only_stubs or prefer_stubs:
|
if only_stubs or prefer_stubs:
|
||||||
return actual_to_stub_names(names, fallback_to_actual=prefer_stubs)
|
return _python_to_stub_names(names, fallback_to_python=prefer_stubs)
|
||||||
else:
|
else:
|
||||||
return try_stub_to_actual_names(names, prefer_stub_to_compiled=True)
|
return _try_stub_to_python_names(names, prefer_stub_to_compiled=True)
|
||||||
|
|
||||||
|
|
||||||
def to_stub(context):
|
def to_stub(context):
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ def _cache_stub_file_map(version_info):
|
|||||||
def import_module_decorator(func):
|
def import_module_decorator(func):
|
||||||
def wrapper(evaluator, import_names, parent_module_context, sys_path, prefer_stubs):
|
def wrapper(evaluator, import_names, parent_module_context, sys_path, prefer_stubs):
|
||||||
try:
|
try:
|
||||||
actual_context_set = evaluator.module_cache.get(import_names)
|
python_context_set = evaluator.module_cache.get(import_names)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if parent_module_context is not None and parent_module_context.is_stub():
|
if parent_module_context is not None and parent_module_context.is_stub():
|
||||||
parent_module_contexts = parent_module_context.non_stub_context_set
|
parent_module_contexts = parent_module_context.non_stub_context_set
|
||||||
@@ -95,25 +95,25 @@ def import_module_decorator(func):
|
|||||||
# ``os.path``, because it's a very important one in Python
|
# ``os.path``, because it's a very important one in Python
|
||||||
# that is being achieved by messing with ``sys.modules`` in
|
# that is being achieved by messing with ``sys.modules`` in
|
||||||
# ``os``.
|
# ``os``.
|
||||||
actual_parent = next(iter(parent_module_contexts))
|
python_parent = next(iter(parent_module_contexts))
|
||||||
if actual_parent is None:
|
if python_parent is None:
|
||||||
actual_parent, = evaluator.import_module(('os',), prefer_stubs=False)
|
python_parent, = evaluator.import_module(('os',), prefer_stubs=False)
|
||||||
actual_context_set = actual_parent.py__getattribute__('path')
|
python_context_set = python_parent.py__getattribute__('path')
|
||||||
else:
|
else:
|
||||||
actual_context_set = ContextSet.from_sets(
|
python_context_set = ContextSet.from_sets(
|
||||||
func(evaluator, import_names, p, sys_path,)
|
func(evaluator, import_names, p, sys_path,)
|
||||||
for p in parent_module_contexts
|
for p in parent_module_contexts
|
||||||
)
|
)
|
||||||
evaluator.module_cache.add(import_names, actual_context_set)
|
evaluator.module_cache.add(import_names, python_context_set)
|
||||||
|
|
||||||
if not prefer_stubs:
|
if not prefer_stubs:
|
||||||
return actual_context_set
|
return python_context_set
|
||||||
|
|
||||||
stub = _try_to_load_stub_cached(evaluator, import_names, actual_context_set,
|
stub = _try_to_load_stub_cached(evaluator, import_names, python_context_set,
|
||||||
parent_module_context, sys_path)
|
parent_module_context, sys_path)
|
||||||
if stub is not None:
|
if stub is not None:
|
||||||
return ContextSet([stub])
|
return ContextSet([stub])
|
||||||
return actual_context_set
|
return python_context_set
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ def _try_to_load_stub_cached(evaluator, import_names, *args, **kwargs):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
def _try_to_load_stub(evaluator, import_names, python_context_set,
|
||||||
parent_module_context, sys_path):
|
parent_module_context, sys_path):
|
||||||
"""
|
"""
|
||||||
Trying to load a stub for a set of import_names.
|
Trying to load a stub for a set of import_names.
|
||||||
@@ -155,7 +155,7 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
init = os.path.join(p, *import_names) + '-stubs' + os.path.sep + '__init__.pyi'
|
init = os.path.join(p, *import_names) + '-stubs' + os.path.sep + '__init__.pyi'
|
||||||
m = _try_to_load_stub_from_file(
|
m = _try_to_load_stub_from_file(
|
||||||
evaluator,
|
evaluator,
|
||||||
actual_context_set,
|
python_context_set,
|
||||||
file_io=FileIO(init),
|
file_io=FileIO(init),
|
||||||
import_names=import_names,
|
import_names=import_names,
|
||||||
)
|
)
|
||||||
@@ -163,7 +163,7 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
return m
|
return m
|
||||||
|
|
||||||
# 2. Try to load pyi files next to py files.
|
# 2. Try to load pyi files next to py files.
|
||||||
for c in actual_context_set:
|
for c in python_context_set:
|
||||||
try:
|
try:
|
||||||
method = c.py__file__
|
method = c.py__file__
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -179,7 +179,7 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
for file_path in file_paths:
|
for file_path in file_paths:
|
||||||
m = _try_to_load_stub_from_file(
|
m = _try_to_load_stub_from_file(
|
||||||
evaluator,
|
evaluator,
|
||||||
actual_context_set,
|
python_context_set,
|
||||||
# The file path should end with .pyi
|
# The file path should end with .pyi
|
||||||
file_io=FileIO(file_path),
|
file_io=FileIO(file_path),
|
||||||
import_names=import_names,
|
import_names=import_names,
|
||||||
@@ -188,12 +188,12 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
return m
|
return m
|
||||||
|
|
||||||
# 3. Try to load typeshed
|
# 3. Try to load typeshed
|
||||||
m = _load_from_typeshed(evaluator, actual_context_set, parent_module_context, import_names)
|
m = _load_from_typeshed(evaluator, python_context_set, parent_module_context, import_names)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
return m
|
return m
|
||||||
|
|
||||||
# 4. Try to load pyi file somewhere if actual_context_set was not defined.
|
# 4. Try to load pyi file somewhere if python_context_set was not defined.
|
||||||
if not actual_context_set:
|
if not python_context_set:
|
||||||
if parent_module_context is not None:
|
if parent_module_context is not None:
|
||||||
try:
|
try:
|
||||||
method = parent_module_context.py__path__
|
method = parent_module_context.py__path__
|
||||||
@@ -210,7 +210,7 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
for p in check_path:
|
for p in check_path:
|
||||||
m = _try_to_load_stub_from_file(
|
m = _try_to_load_stub_from_file(
|
||||||
evaluator,
|
evaluator,
|
||||||
actual_context_set,
|
python_context_set,
|
||||||
file_io=FileIO(os.path.join(p, *names_for_path) + '.pyi'),
|
file_io=FileIO(os.path.join(p, *names_for_path) + '.pyi'),
|
||||||
import_names=import_names,
|
import_names=import_names,
|
||||||
)
|
)
|
||||||
@@ -222,7 +222,7 @@ def _try_to_load_stub(evaluator, import_names, actual_context_set,
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _load_from_typeshed(evaluator, actual_context_set, parent_module_context, import_names):
|
def _load_from_typeshed(evaluator, python_context_set, parent_module_context, import_names):
|
||||||
import_name = import_names[-1]
|
import_name = import_names[-1]
|
||||||
map_ = None
|
map_ = None
|
||||||
if len(import_names) == 1:
|
if len(import_names) == 1:
|
||||||
@@ -240,13 +240,13 @@ def _load_from_typeshed(evaluator, actual_context_set, parent_module_context, im
|
|||||||
if path is not None:
|
if path is not None:
|
||||||
return _try_to_load_stub_from_file(
|
return _try_to_load_stub_from_file(
|
||||||
evaluator,
|
evaluator,
|
||||||
actual_context_set,
|
python_context_set,
|
||||||
file_io=FileIO(path),
|
file_io=FileIO(path),
|
||||||
import_names=import_names,
|
import_names=import_names,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _try_to_load_stub_from_file(evaluator, actual_context_set, file_io, import_names):
|
def _try_to_load_stub_from_file(evaluator, python_context_set, file_io, import_names):
|
||||||
try:
|
try:
|
||||||
stub_module_node = evaluator.parse(
|
stub_module_node = evaluator.parse(
|
||||||
file_io=file_io,
|
file_io=file_io,
|
||||||
@@ -258,19 +258,19 @@ def _try_to_load_stub_from_file(evaluator, actual_context_set, file_io, import_n
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return create_stub_module(
|
return create_stub_module(
|
||||||
evaluator, actual_context_set, stub_module_node, file_io,
|
evaluator, python_context_set, stub_module_node, file_io,
|
||||||
import_names
|
import_names
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_stub_module(evaluator, actual_context_set, stub_module_node, file_io, import_names):
|
def create_stub_module(evaluator, python_context_set, stub_module_node, file_io, import_names):
|
||||||
if import_names == ('typing',):
|
if import_names == ('typing',):
|
||||||
module_cls = TypingModuleWrapper
|
module_cls = TypingModuleWrapper
|
||||||
else:
|
else:
|
||||||
module_cls = StubModuleContext
|
module_cls = StubModuleContext
|
||||||
file_name = os.path.basename(file_io.path)
|
file_name = os.path.basename(file_io.path)
|
||||||
stub_module_context = module_cls(
|
stub_module_context = module_cls(
|
||||||
actual_context_set, evaluator, stub_module_node,
|
python_context_set, evaluator, stub_module_node,
|
||||||
file_io=file_io,
|
file_io=file_io,
|
||||||
string_names=import_names,
|
string_names=import_names,
|
||||||
# The code was loaded with latest_grammar, so use
|
# The code was loaded with latest_grammar, so use
|
||||||
|
|||||||
Reference in New Issue
Block a user