diff --git a/mypy/build.py b/mypy/build.py index f388f0909854..08e85dd28624 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2238,7 +2238,7 @@ def semantic_analysis_pass1(self) -> None: analyzer = SemanticAnalyzerPreAnalysis() with self.wrap_context(): analyzer.visit_file(self.tree, self.xpath, self.id, options) - self.manager.errors.set_unreachable_lines(self.xpath, self.tree.unreachable_lines) + self.manager.errors.set_skipped_lines(self.xpath, self.tree.skipped_lines) # TODO: Do this while constructing the AST? self.tree.names = SymbolTable() if not self.tree.is_stub: diff --git a/mypy/errors.py b/mypy/errors.py index b230b3baa3f6..0e61f5ecf0cd 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -223,8 +223,9 @@ class Errors: # (path -> line -> error-codes) ignored_lines: dict[str, dict[int, list[str]]] - # Lines that are statically unreachable (e.g. due to platform/version check). - unreachable_lines: dict[str, set[int]] + # Lines that were skipped during semantic analysis e.g. due to ALWAYS_FALSE, MYPY_FALSE, + # or platform/version checks. Those lines would not be type-checked. + skipped_lines: dict[str, set[int]] # Lines on which an error was actually ignored. used_ignored_lines: dict[str, dict[int, list[str]]] @@ -281,7 +282,7 @@ def initialize(self) -> None: self.import_ctx = [] self.function_or_member = [None] self.ignored_lines = {} - self.unreachable_lines = {} + self.skipped_lines = {} self.used_ignored_lines = defaultdict(lambda: defaultdict(list)) self.ignored_files = set() self.only_once_messages = set() @@ -330,8 +331,8 @@ def set_file_ignored_lines( if ignore_all: self.ignored_files.add(file) - def set_unreachable_lines(self, file: str, unreachable_lines: set[int]) -> None: - self.unreachable_lines[file] = unreachable_lines + def set_skipped_lines(self, file: str, skipped_lines: set[int]) -> None: + self.skipped_lines[file] = skipped_lines def current_target(self) -> str | None: """Retrieves the current target from the associated scope. @@ -631,7 +632,7 @@ def generate_unused_ignore_errors(self, file: str) -> None: ignored_lines = self.ignored_lines[file] used_ignored_lines = self.used_ignored_lines[file] for line, ignored_codes in ignored_lines.items(): - if line in self.unreachable_lines[file]: + if line in self.skipped_lines[file]: continue if codes.UNUSED_IGNORE.code in ignored_codes: continue diff --git a/mypy/nodes.py b/mypy/nodes.py index 4e29a434d7fe..2f4f3f788385 100644 --- a/mypy/nodes.py +++ b/mypy/nodes.py @@ -287,7 +287,7 @@ class MypyFile(SymbolNode): "names", "imports", "ignored_lines", - "unreachable_lines", + "skipped_lines", "is_stub", "is_cache_skeleton", "is_partial_stub_package", @@ -314,8 +314,9 @@ class MypyFile(SymbolNode): # If the value is empty, ignore all errors; otherwise, the list contains all # error codes to ignore. ignored_lines: dict[int, list[str]] - # Lines that are statically unreachable (e.g. due to platform/version check). - unreachable_lines: set[int] + # Lines that were skipped during semantic analysis e.g. due to ALWAYS_FALSE, MYPY_FALSE, + # or platform/version checks. Those lines would not be type-checked. + skipped_lines: set[int] # Is this file represented by a stub file (.pyi)? is_stub: bool # Is this loaded from the cache and thus missing the actual body of the file? @@ -348,7 +349,7 @@ def __init__( self.ignored_lines = ignored_lines else: self.ignored_lines = {} - self.unreachable_lines = set() + self.skipped_lines = set() self.path = "" self.is_stub = False diff --git a/mypy/semanal_pass1.py b/mypy/semanal_pass1.py index 659f33e65ead..2df06feacca8 100644 --- a/mypy/semanal_pass1.py +++ b/mypy/semanal_pass1.py @@ -62,7 +62,7 @@ def visit_file(self, file: MypyFile, fnam: str, mod_id: str, options: Options) - self.cur_mod_node = file self.options = options self.is_global_scope = True - self.unreachable_lines: set[int] = set() + self.skipped_lines: set[int] = set() for i, defn in enumerate(file.defs): defn.accept(self) @@ -74,10 +74,10 @@ def visit_file(self, file: MypyFile, fnam: str, mod_id: str, options: Options) - next_def, last = file.defs[i + 1], file.defs[-1] if last.end_line is not None: # We are on a Python version recent enough to support end lines. - self.unreachable_lines |= set(range(next_def.line, last.end_line + 1)) + self.skipped_lines |= set(range(next_def.line, last.end_line + 1)) del file.defs[i + 1 :] break - file.unreachable_lines = self.unreachable_lines + file.skipped_lines = self.skipped_lines def visit_func_def(self, node: FuncDef) -> None: old_global_scope = self.is_global_scope @@ -127,7 +127,7 @@ def visit_block(self, b: Block) -> None: if b.is_unreachable: if b.end_line is not None: # We are on a Python version recent enough to support end lines. - self.unreachable_lines |= set(range(b.line, b.end_line + 1)) + self.skipped_lines |= set(range(b.line, b.end_line + 1)) return super().visit_block(b) diff --git a/mypy/server/update.py b/mypy/server/update.py index 7b439eb0ab9f..dafed6642d1e 100644 --- a/mypy/server/update.py +++ b/mypy/server/update.py @@ -986,7 +986,7 @@ def key(node: FineGrainedDeferredNode) -> int: manager.errors.set_file_ignored_lines( file_node.path, file_node.ignored_lines, options.ignore_errors or state.ignore_all ) - manager.errors.set_unreachable_lines(file_node.path, file_node.unreachable_lines) + manager.errors.set_skipped_lines(file_node.path, file_node.skipped_lines) targets = set() for node in nodes: