forked from VimPlug/jedi
Use one single way to convert stubs to Python, see #1466
This commit is contained in:
@@ -75,7 +75,7 @@ def _try_stub_to_python_names(names, prefer_stub_to_compiled=False):
|
|||||||
for n in converted_names:
|
for n in converted_names:
|
||||||
yield n
|
yield n
|
||||||
continue
|
continue
|
||||||
yield name
|
yield name
|
||||||
|
|
||||||
|
|
||||||
def _load_stub_module(module):
|
def _load_stub_module(module):
|
||||||
@@ -99,32 +99,22 @@ def _python_to_stub_names(names, fallback_to_python=False):
|
|||||||
yield name
|
yield name
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if name.is_import():
|
if name.api_type == 'module':
|
||||||
for new_name in name.goto():
|
values = convert_values(name.infer(), only_stubs=True)
|
||||||
# Imports don't need to be converted, because they are already
|
if values:
|
||||||
# stubs if possible.
|
for v in values:
|
||||||
if fallback_to_python or new_name.is_stub():
|
yield v.name
|
||||||
yield new_name
|
|
||||||
continue
|
|
||||||
|
|
||||||
name_list = name.get_qualified_names()
|
|
||||||
stubs = NO_VALUES
|
|
||||||
if name_list is not None:
|
|
||||||
stub_module = _load_stub_module(module_context.get_value())
|
|
||||||
if stub_module is not None:
|
|
||||||
stubs = ValueSet({stub_module})
|
|
||||||
for name in name_list[:-1]:
|
|
||||||
stubs = stubs.py__getattribute__(name)
|
|
||||||
if stubs and name_list:
|
|
||||||
new_names = stubs.goto(name_list[-1])
|
|
||||||
for new_name in new_names:
|
|
||||||
yield new_name
|
|
||||||
if new_names:
|
|
||||||
continue
|
continue
|
||||||
elif stubs:
|
else:
|
||||||
for c in stubs:
|
v = name.get_defining_qualified_value()
|
||||||
yield c.name
|
if v is not None:
|
||||||
continue
|
converted = to_stub(v)
|
||||||
|
if converted:
|
||||||
|
converted_names = converted.goto(name.get_public_name())
|
||||||
|
if converted_names:
|
||||||
|
for n in converted_names:
|
||||||
|
yield n
|
||||||
|
continue
|
||||||
if fallback_to_python:
|
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.
|
||||||
@@ -158,7 +148,6 @@ def convert_values(values, only_stubs=False, prefer_stubs=False, ignore_compiled
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO merge with _python_to_stub_names?
|
|
||||||
def to_stub(value):
|
def to_stub(value):
|
||||||
if value.is_stub():
|
if value.is_stub():
|
||||||
return ValueSet([value])
|
return ValueSet([value])
|
||||||
|
|||||||
Reference in New Issue
Block a user