diff --git a/pytype/pytd/visitors.py b/pytype/pytd/visitors.py index e354ed21a..f2a83c18c 100644 --- a/pytype/pytd/visitors.py +++ b/pytype/pytd/visitors.py @@ -536,6 +536,14 @@ def VisitNamedType(self, t): item = self._ResolveUsingStarImport(module, name) if item is None: raise KeyError(f"No {name} in module {module_name}") from e + if isinstance(item, pytd.Alias): + # This is a workaround for aliases that reference other aliases not being + # fully resolved before LookupExternalTypes() runs. + lookup_local = LookupLocalTypes() + lookup_local.unit = module + new_item = item.Visit(lookup_local) + if lookup_local.local_names: + item = new_item if not self._in_generic_type and isinstance(item, pytd.Alias): # If `item` contains type parameters and is not inside a GenericType, then # we replace the parameters with Any.