mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-09 05:22:19 +08:00
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:
|
||||
yield n
|
||||
continue
|
||||
yield name
|
||||
yield name
|
||||
|
||||
|
||||
def _load_stub_module(module):
|
||||
@@ -99,32 +99,22 @@ def _python_to_stub_names(names, fallback_to_python=False):
|
||||
yield name
|
||||
continue
|
||||
|
||||
if name.is_import():
|
||||
for new_name in name.goto():
|
||||
# Imports don't need to be converted, because they are already
|
||||
# stubs if possible.
|
||||
if fallback_to_python or new_name.is_stub():
|
||||
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:
|
||||
if name.api_type == 'module':
|
||||
values = convert_values(name.infer(), only_stubs=True)
|
||||
if values:
|
||||
for v in values:
|
||||
yield v.name
|
||||
continue
|
||||
elif stubs:
|
||||
for c in stubs:
|
||||
yield c.name
|
||||
continue
|
||||
else:
|
||||
v = name.get_defining_qualified_value()
|
||||
if v is not None:
|
||||
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:
|
||||
# This is the part where if we haven't found anything, just return
|
||||
# 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):
|
||||
if value.is_stub():
|
||||
return ValueSet([value])
|
||||
|
||||
Reference in New Issue
Block a user