Skip to content

Commit a0e9a99

Browse files
authored
Minor refactoring of new semantic analyzer and daemon (#6837)
1 parent 466bff8 commit a0e9a99

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

mypy/newsemanal/semanal.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ def analyze_member_lvalue(self, lval: MemberExpr, explicit_type: bool, is_final:
25802580
lval.accept(self)
25812581
if self.is_self_member_ref(lval):
25822582
assert self.type, "Self member outside a class"
2583-
cur_node = self.type.names.get(lval.name, None)
2583+
cur_node = self.type.names.get(lval.name)
25842584
node = self.type.get(lval.name)
25852585
if cur_node and is_final:
25862586
# Overrides will be checked in type checker.
@@ -2591,11 +2591,12 @@ def analyze_member_lvalue(self, lval: MemberExpr, explicit_type: bool, is_final:
25912591
cur_node.node.is_inferred and explicit_type):
25922592
self.attribute_already_defined(lval.name, lval, cur_node)
25932593
# If the attribute of self is not defined in superclasses, create a new Var, ...
2594-
if ((node is None or isinstance(node.node, Var) and node.node.is_abstract_var) or
2594+
if (node is None
2595+
or (isinstance(node.node, Var) and node.node.is_abstract_var)
25952596
# ... also an explicit declaration on self also creates a new Var.
25962597
# Note that `explicit_type` might has been erased for bare `Final`,
25972598
# so we also check if `is_final` is passed.
2598-
(cur_node is None and (explicit_type or is_final))):
2599+
or (cur_node is None and (explicit_type or is_final))):
25992600
if self.type.is_protocol and node is None:
26002601
self.fail("Protocol members cannot be defined via assignment to self", lval)
26012602
else:

mypy/newsemanal/semanal_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def cleanup_builtin_scc(state: 'State') -> None:
9696
remove_imported_names_from_symtable(state.tree.names, 'builtins')
9797

9898

99-
def process_selected_targets(state: 'State', nodes: List[FineGrainedDeferredNode],
100-
graph: 'Graph', strip_patches: List[Callable[[], None]]) -> None:
99+
def semantic_analysis_for_targets(state: 'State', nodes: List[FineGrainedDeferredNode],
100+
graph: 'Graph', strip_patches: List[Callable[[], None]]) -> None:
101101
"""Semantically analyze only selected nodes in a given module.
102102
103103
This essentially mirrors the logic of semantic_analysis_for_scc()

mypy/server/update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
from mypy.server.astdiff import (
137137
snapshot_symbol_table, compare_symbol_table_snapshots, SnapshotItem
138138
)
139-
from mypy.newsemanal.semanal_main import semantic_analysis_for_scc, process_selected_targets
139+
from mypy.newsemanal.semanal_main import semantic_analysis_for_scc, semantic_analysis_for_targets
140140
from mypy.server.astmerge import merge_asts
141141
from mypy.server.aststrip import strip_target
142142
from mypy.server.aststripnew import strip_target_new
@@ -955,7 +955,7 @@ def key(node: FineGrainedDeferredNode) -> int:
955955
if not options.new_semantic_analyzer:
956956
re_analyze_nodes(file_node, nodes, manager, options)
957957
else:
958-
process_selected_targets(graph[module_id], nodes, graph, patches)
958+
semantic_analysis_for_targets(graph[module_id], nodes, graph, patches)
959959
# Merge symbol tables to preserve identities of AST nodes. The file node will remain
960960
# the same, but other nodes may have been recreated with different identities, such as
961961
# NamedTuples defined using assignment statements.

0 commit comments

Comments
 (0)