Skip to content

Fix PoChecker instance isolation, method naming, and boolean simplification#6

Merged
admdly merged 2 commits into
mainfrom
copilot/fix-class-variable-total-issues
May 8, 2026
Merged

Fix PoChecker instance isolation, method naming, and boolean simplification#6
admdly merged 2 commits into
mainfrom
copilot/fix-class-variable-total-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 8, 2026

totalIssues was a class variable, causing counts to accumulate across multiple PoChecker instances. The custom dictionary suggestion method also had a typo in its name (CustomDicCustomDict), and a redundant ternary was used to produce a boolean.

Changes

  • Instance variable: Moved totalIssues = 0 from class body to self.totalIssues = 0 in __init__, ensuring each instance maintains its own count.
  • Method rename: suggestCorrectionsFromCustomDicsuggestCorrectionsFromCustomDict (spelling fix); updated all call sites accordingly.
  • Boolean simplification: Replaced True if <expr> else False with bool(<expr>).
# Before — shared across all instances
class PoChecker:
    totalIssues = 0

# After — isolated per instance
def __init__(self, ...):
    ...
    self.totalIssues = 0
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"Class variable `totalIssues` should be an instance variable instead. As a class variable, it will be shared across all instances of `PoChecker`, causing the count to accumulate incorrectly when multiple instances are created. Move this initialization to `__init__` as `self.totalIssues = 0`.","fixFiles":[{"filePath":"check.py","diff":"diff --git a/check.py b/check.py\n--- a/check.py\n+++ b/check.py\n@@ -27,7 +27,6 @@\n \n # poChecker class - does all the main work\n class PoChecker:\n-    totalIssues = 0\n \n     def __init__(\n         self,\n@@ -57,6 +56,7 @@\n         self.check_translation = check_translation\n         self.custom_dict = custom_dict\n         self.verbose = verbose\n+        self.totalIssues = 0\n \n     # Main check loop\n     def process(self):\n"}]},{"message":"Corrected spelling of 'CustomDic' to 'CustomDict' in method name.","fixFiles":[{"filePath":"check.py","diff":"diff --git a/check.py b/check.py\n--- a/check.py\n+++ b/check.py\n@@ -82,7 +82,7 @@\n                     self.outputIssue(issue)\n \n     # Suggests a spelling correction using the custom dictionary\n-    def suggestCorrectionsFromCustomDic(self, typo, distance_limit=3):\n+    def suggestCorrectionsFromCustomDict(self, typo, distance_limit=3):\n         min_dist = distance_limit + 1\n         suggested_word = None\n \n"}]},{"message":"The conditional expression can be simplified to `hasSuggestion = bool(issue.replacements and issue.replacements[0])` for better readability.","fixFiles":[{"filePath":"check.py","diff":"diff --git a/check.py b/check.py\n--- a/check.py\n+++ b/check.py\n@@ -124,7 +124,7 @@\n             issue.offsetInContext : issue.offsetInContext + issue.errorLength\n         ]\n \n-        hasSuggestion = True if issue.replacements and issue.replacements[0] else False\n+        hasSuggestion = bool(issue.replacements and issue.replacements[0])\n \n         # Our method for giving suggestions is less robust, we should reduce the allowed edit distance if a suggestion was already provided\n         if hasSuggestion:\n"}]},{"message":"The variable name `suggestionFromCustomDict` is inconsistent with the method name `suggestCorrectionsFromCustomDic`. Since the method name has a spelling issue (Dic vs Dict), this creates additional confusion. Once the method name is corrected, update this variable name to match.","fixFiles":[{"filePath":"check.py","diff":"diff --git a/check.py b/check.py\n--- a/check.py\n+++ b/check.py\n@@ -128,23 +128,23 @@\n \n         # Our method for giving suggestions is less robust, we should reduce the allowed edit distance if a suggestion was already provided\n         if hasSuggestion:\n-            suggestionFromCustomDict = self.suggestCorrectionsFromCustomDic(typo, 2)\n+            suggestionFromCustomDic = self.suggestCorrectionsFromCustomDic(typo, 2)\n         else:\n-            suggestionFromCustomDict = self.suggestCorrectionsFromCustomDic(typo, 3)\n+            suggestionFromCustomDic = self.suggestCorrectionsFromCustomDic(typo, 3)\n \n         if hasSuggestion:\n             # Ensure we are providing the suggestion with the smallest edit distance\n-            if suggestionFromCustomDict:\n+            if suggestionFromCustomDic:\n                 suggestion = (\n                     issue.replacements[0]\n                     if distance(typo, issue.replacements[0], score_cutoff=3)\n-                    < distance(typo, suggestionFromCustomDict, score_cutoff=3)\n-                    else suggestionFromCustomDict\n+                    < distance(typo, suggestionFromCustomDic, score_cutoff=3)\n+                    else suggestionFromCustomDic\n                 )\n             else:\n                 suggestion = issue.replacements[0]\n         else:\n-            suggestion = suggestionFromCustomDict\n+            suggestion = suggestionFromCustomDic\n \n         if suggestion:\n             print(Fore.GREEN + f\"{offset}{suggestion}\")\n"}]},{"message":"The variable name `suggestionFromCustomDict` is inconsistent with the method name `suggestCorrectionsFromCustomDic`. Since the method name has a spelling issue (Dic vs Dict), this creates additional confusion. Once the method name is corrected, update this variable name to match.","fixFiles":[{"filePath":"check.py","diff":"diff --git a/check.py b/check.py\n--- a/check.py\n+++ b/check.py\n@@ -128,9 +128,9 @@\n \n         # Our method for giving suggestions is less robust, we should reduce the allowed edit distance if a suggestion was already provided\n         if hasSuggestion:\n-            suggestionFromCustomDict = self.suggestCorrectionsFromCustomDic(typo, 2)\n+            suggestionFromCustomDict = self.suggestCorrectionsFromCustomDict(typo, 2)\n         else:\n-            suggestionFromCustomDict = self.suggestCorrectionsFromCustomDic(typo, 3)\n+...

Copilot AI changed the title [WIP] Fix class variable totalIssues to be an instance variable Fix PoChecker instance isolation, method naming, and boolean simplification May 8, 2026
Copilot AI requested a review from admdly May 8, 2026 07:27
Copilot finished work on behalf of admdly May 8, 2026 07:27
@admdly admdly marked this pull request as ready for review May 8, 2026 07:29
@admdly admdly merged commit 48c07d5 into main May 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants