Skip to content

Commit 6bf9e70

Browse files
committed
Move a check out of --enable-nested-classes.
The --enable-nested-classes flag guards several related changes that generate new type errors. This moves out one of the smaller changes (in terms of breakage) from behind the flag. I've also sent out patches for the breakages. PiperOrigin-RevId: 446018474
1 parent 5710b85 commit 6bf9e70

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

pytype/load_pytd.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,9 @@ def log_module_not_found(self, module_name):
286286
class _Resolver:
287287
"""Resolve symbols in a pytd tree."""
288288

289-
def __init__(self, builtins_ast, enable_nested_classes):
289+
def __init__(self, builtins_ast):
290290
self.builtins_ast = builtins_ast
291291
self.allow_singletons = False
292-
self._enable_nested_classes = enable_nested_classes
293292

294293
def _lookup(self, visitor, mod_ast, lookup_ast):
295294
if lookup_ast:
@@ -298,9 +297,7 @@ def _lookup(self, visitor, mod_ast, lookup_ast):
298297
return mod_ast
299298

300299
def resolve_local_types(self, mod_ast, *, lookup_ast=None):
301-
local_lookup = visitors.LookupLocalTypes(
302-
self.allow_singletons,
303-
enable_nested_classes=self._enable_nested_classes)
300+
local_lookup = visitors.LookupLocalTypes(self.allow_singletons)
304301
return self._lookup(local_lookup, mod_ast, lookup_ast)
305302

306303
def resolve_builtin_types(self, mod_ast, *, lookup_ast=None):
@@ -376,7 +373,7 @@ def __init__(self, options, modules=None):
376373
self._path_finder = _PathFinder(options)
377374
self._builtin_loader = builtin_stubs.BuiltinLoader(
378375
parser.PyiOptions.from_toplevel_options(options))
379-
self._resolver = _Resolver(self.builtins, options.enable_nested_classes)
376+
self._resolver = _Resolver(self.builtins)
380377
self._import_name_cache = {} # performance cache
381378
self._aliases = {}
382379
self._prefixes = set()

pytype/pytd/visitors.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,11 @@ def VisitTypeDeclUnit(self, node):
623623
class LookupLocalTypes(_RemoveTypeParametersFromGenericAny, _ToTypeVisitor):
624624
"""Look up local identifiers. Must be called on a TypeDeclUnit."""
625625

626-
def __init__(self, allow_singletons=False, toplevel=True,
627-
enable_nested_classes=True):
626+
def __init__(self, allow_singletons=False, toplevel=True):
628627
super().__init__(allow_singletons)
629628
self._toplevel = toplevel
630629
self.local_names = set()
631630
self.class_names = []
632-
self._enable_nested_classes = enable_nested_classes
633631

634632
def EnterTypeDeclUnit(self, unit):
635633
self.unit = unit
@@ -746,7 +744,7 @@ def VisitNamedType(self, node):
746744
return resolved_node
747745

748746
def VisitClassType(self, t):
749-
if not t.cls and self._enable_nested_classes:
747+
if not t.cls:
750748
if t.name == self.class_names[-1]:
751749
full_name = ".".join(self.class_names)
752750
lookup_type = pytd.NamedType(full_name)

0 commit comments

Comments
 (0)