def _python_to_stub_names(names, fallback_to_python=False):
    for name in names:
        module_context = name.get_root_context()
        if module_context.is_stub():
            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:
                continue
        elif stubs:
            for c in stubs:
                yield c.name
            continue
        if fallback_to_python:
            # This is the part where if we haven't found anything, just return
            # the stub name.
            yield name