Skip to content

Commit 532a79c

Browse files
rwbartongvanrossum
authored andcommitted
Remove dead 'symtable' and 'locals' fields of TypeChecker
'locals' is effectively dead since it is always either None or an empty SymbolTable.
1 parent b8b0b2f commit 532a79c

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

mypy/checker.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,6 @@ class TypeChecker(NodeVisitor[Type]):
328328
is_stub = False
329329
# Error message reporter
330330
errors = None # type: Errors
331-
# SymbolNode table for the whole program
332-
symtable = None # type: SymbolTable
333331
# Utility for generating messages
334332
msg = None # type: MessageBuilder
335333
# Types of type checked nodes
@@ -355,7 +353,6 @@ class TypeChecker(NodeVisitor[Type]):
355353
# Stack of collections of variables with partial types
356354
partial_types = None # type: List[Dict[Var, Context]]
357355
globals = None # type: SymbolTable
358-
locals = None # type: SymbolTable
359356
modules = None # type: Dict[str, MypyFile]
360357
# Nodes that couldn't be checked because some types weren't available. We'll run
361358
# another pass and try these again.
@@ -378,8 +375,7 @@ def __init__(self, errors: Errors, modules: Dict[str, MypyFile],
378375
check_untyped_defs=False) -> None:
379376
"""Construct a type checker.
380377
381-
Use errors to report type check errors. Assume symtable has been
382-
populated by the semantic analyzer.
378+
Use errors to report type check errors.
383379
"""
384380
self.errors = errors
385381
self.modules = modules
@@ -409,7 +405,6 @@ def visit_file(self, file_node: MypyFile, path: str) -> None:
409405
self.errors.set_file(path)
410406
self.errors.set_ignored_lines(file_node.ignored_lines)
411407
self.globals = file_node.names
412-
self.locals = None
413408
self.weak_opts = file_node.weak_opts
414409
self.enter_partial_types()
415410

@@ -656,8 +651,6 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: str) -> None:
656651
else:
657652
fdef = None
658653

659-
self.enter()
660-
661654
if fdef:
662655
# Check if __init__ has an invalid, non-None return type.
663656
if (fdef.info and fdef.name() == '__init__' and
@@ -740,7 +733,6 @@ def is_implicit_any(t: Type) -> bool:
740733

741734
self.return_types.pop()
742735

743-
self.leave()
744736
self.binder = old_binder
745737

746738
def check_reverse_op_method(self, defn: FuncItem, typ: CallableType,
@@ -2241,9 +2233,7 @@ def lookup(self, name: str, kind: int) -> SymbolTableNode:
22412233
"""Look up a definition from the symbol table with the given name.
22422234
TODO remove kind argument
22432235
"""
2244-
if self.locals is not None and name in self.locals:
2245-
return self.locals[name]
2246-
elif name in self.globals:
2236+
if name in self.globals:
22472237
return self.globals[name]
22482238
else:
22492239
b = self.globals.get('__builtins__', None)
@@ -2263,12 +2253,6 @@ def lookup_qualified(self, name: str) -> SymbolTableNode:
22632253
n = cast(MypyFile, n.names.get(parts[i], None).node)
22642254
return n.names[parts[-1]]
22652255

2266-
def enter(self) -> None:
2267-
self.locals = SymbolTable()
2268-
2269-
def leave(self) -> None:
2270-
self.locals = None
2271-
22722256
def enter_partial_types(self) -> None:
22732257
"""Push a new scope for collecting partial types."""
22742258
self.partial_types.append({})

0 commit comments

Comments
 (0)