Use one single way to convert stubs to Python, see #1466

This commit is contained in:
Dave Halter
2020-01-07 10:02:31 +01:00
parent 9b9cacfbf9
commit a17b56f260
+14 -25
View File
@@ -99,31 +99,21 @@ 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 continue
else:
name_list = name.get_qualified_names() v = name.get_defining_qualified_value()
stubs = NO_VALUES if v is not None:
if name_list is not None: converted = to_stub(v)
stub_module = _load_stub_module(module_context.get_value()) if converted:
if stub_module is not None: converted_names = converted.goto(name.get_public_name())
stubs = ValueSet({stub_module}) if converted_names:
for name in name_list[:-1]: for n in converted_names:
stubs = stubs.py__getattribute__(name) yield n
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
elif stubs:
for c in stubs:
yield c.name
continue 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
@@ -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])