From e304d4663713c41261e9d160e2f353e24e2624db Mon Sep 17 00:00:00 2001 From: Zanie Date: Fri, 27 Oct 2023 12:21:03 -0500 Subject: [PATCH] Add mutability note for `RuleChanges` --- python/ruff-ecosystem/ruff_ecosystem/check.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/python/ruff-ecosystem/ruff_ecosystem/check.py b/python/ruff-ecosystem/ruff_ecosystem/check.py index b266a3e028..ce760d44ba 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/check.py +++ b/python/ruff-ecosystem/ruff_ecosystem/check.py @@ -76,17 +76,17 @@ def markdown_check_result(result: Result) -> str: return "\u2705 ecosystem check detected no linter changes." # Summarize the total changes - changes = ( + change_summary = ( f"{markdown_plus_minus(total_added, total_removed)} violations, " f"{markdown_plus_minus(total_added_fixes, total_removed_fixes)} fixes" f"in {len(result.completed)} projects" ) if error_count: s = "s" if error_count != 1 else "" - changes += f"; {error_count} project error{s}" + change_summary += f"; {error_count} project error{s}" lines.append( - f"\u2139\ufe0f ecosystem check **detected linter changes**. ({changes})" + f"\u2139\ufe0f ecosystem check **detected linter changes**. ({change_summary})" ) lines.append("") @@ -234,7 +234,10 @@ def markdown_check_result(result: Result) -> str: @dataclass(frozen=True) class RuleChanges: """ - The number of additions and removals by rule code + The number of additions and removals by rule code. + + While the attributes are frozen to avoid accidentally changing the value of an attribute, + the counters themselves are mutable and this class can be mutated with `+` and `update`. """ added_violations: Counter = field(default_factory=Counter) @@ -254,7 +257,7 @@ class RuleChanges: if not isinstance(other, type(self)): return NotImplemented - new = RuleChanges() + new = type(self)() new.update(self) new.update(other) return new