Skip to content

Commit

Permalink
Fix a bug in how we resolve aliases in pyi files.
Browse files Browse the repository at this point in the history
Fixes a bug that affects typeshed's pytype_test. See
python/typeshed#11333 for context. I wasn't able to
write a test for this because it's triggered by some complicated combination of
mutually dependent pyi files and mutually recursive aliases.

PiperOrigin-RevId: 609414132
  • Loading branch information
rchen152 committed Feb 27, 2024
1 parent 54c0e05 commit b8a6fb1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pytype/pytd/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b8a6fb1

Please sign in to comment.