Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename unreachable_lines to skipped_lines #15483

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ 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 (would not be type-checked).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the examples of a reason to skip: e.g. due to platform/version check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, always-true: 5b6dc5f

skipped_lines: dict[str, set[int]]

# Lines on which an error was actually ignored.
used_ignored_lines: dict[str, dict[int, list[str]]]
Expand Down Expand Up @@ -281,7 +281,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()
Expand Down Expand Up @@ -330,8 +330,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.
Expand Down Expand Up @@ -631,7 +631,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
Expand Down
8 changes: 4 additions & 4 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class MypyFile(SymbolNode):
"names",
"imports",
"ignored_lines",
"unreachable_lines",
"skipped_lines",
"is_stub",
"is_cache_skeleton",
"is_partial_stub_package",
Expand All @@ -314,8 +314,8 @@ 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 (would not be type-checked).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the examples of a reason to skip: e.g. due to platform/version check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, always-true: 5b6dc5f

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?
Expand Down Expand Up @@ -348,7 +348,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
Expand Down
8 changes: 4 additions & 4 deletions mypy/semanal_pass1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion mypy/server/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down