Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1360352?usp=email )

Change subject: Fix B045 and B046 lint warnings
......................................................................

Fix B045 and B046 lint warnings

Use dictionary comprehensions to avoid sharing mutable plural rule
dictionaries and rename the inner loop variable to `ref_match` to
avoid shadowing.

Bug: T442813
Change-Id: I152664218cf36b80676040690946a0ba77b9a3ce
---
M .pre-commit-config.yaml
M pywikibot/plural.py
M scripts/reflinks.py
3 files changed, 30 insertions(+), 22 deletions(-)

Approvals:
  Xqt: Verified; Looks good to me, approved
  jenkins-bot: Verified




diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0abee10..11fef2b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -114,7 +114,7 @@
           - --config=tox.ini
         # Due to incompatibilities between packages the order matters.
         additional_dependencies:
-          - flake8-bugbear>=25.11.29
+          - flake8-bugbear>=26.10.27
           - flake8-print>=5.0.0
           - pep8-naming>=0.15.1
   - repo: https://github.com/pre-commit/mirrors-mypy
diff --git a/pywikibot/plural.py b/pywikibot/plural.py
index ad2c4da..7efa2a8 100644
--- a/pywikibot/plural.py
+++ b/pywikibot/plural.py
@@ -89,26 +89,34 @@
            3},
 }

-plural_rules.update(
-    dict.fromkeys(
-        ['ay', 'bo', 'cgg', 'dz', 'fa', 'id', 'ja', 'jbo', 'ka', 'kk', 'km',
-         'ko', 'ky', 'lo', 'ms', 'my', 'sah', 'su', 'th', 'tt', 'ug', 'vi',
-         'wo', 'zh', 'zh-hans', 'zh-hant', 'zh-tw'],
-        {'nplurals': 1, 'plural': 0}))
+plural_rules.update({
+    code: {'nplurals': 1, 'plural': 0}
+    for code in (
+        'ay', 'bo', 'cgg', 'dz', 'fa', 'id', 'ja', 'jbo', 'ka', 'kk', 'km',
+        'ko', 'ky', 'lo', 'ms', 'my', 'sah', 'su', 'th', 'tt', 'ug', 'vi',
+        'wo', 'zh', 'zh-hans', 'zh-hant', 'zh-tw',
+    )
+})

-plural_rules.update(
-    dict.fromkeys(
-        ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'fr', 'gun', 'ln', 'mfe', 'mg',
-         'mi', 'oc', 'pt-br', 'ti', 'tr', 'uz', 'wa'],
-        {'nplurals': 2, 'plural': lambda n: (n > 1)}))
+plural_rules.update({
+    code: {'nplurals': 2, 'plural': lambda n: n > 1}
+    for code in (
+        'ach', 'ak', 'am', 'arn', 'br', 'fil', 'fr', 'gun', 'ln', 'mfe', 'mg',
+        'mi', 'oc', 'pt-br', 'ti', 'tr', 'uz', 'wa',
+    )
+})

-plural_rules.update(
-    dict.fromkeys(
-        ['be', 'bs', 'csb', 'hr', 'ru', 'sr', 'uk'],
-        {'nplurals': 3, 'plural': lambda n:
-         0 if n % 10 == 1 and n % 100 != 11 else
-         1 if (2 <= (n % 10) <= 4) and (n % 100 < 10 or n % 100 >= 20)
-         else 2}))
+plural_rules.update({
+    code: {
+        'nplurals': 3,
+        'plural': lambda n:
+            0 if n % 10 == 1 and n % 100 != 11 else
+            1 if (2 <= (n % 10) <= 4)
+            and (n % 100 < 10 or n % 100 >= 20) else
+            2,
+    }
+    for code in ('be', 'bs', 'csb', 'hr', 'ru', 'sr', 'uk')
+})


 def plural_rule(lang: str) -> PluralRule:
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 52333b7..8e62de2 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -401,10 +401,10 @@

                 # replace multiple identical references with repeated ref
                 repeated_ref = f'<ref {group}{name=!s} />'
-                for ref in v[IX.reflist][1:]:
+                for ref_match in v[IX.reflist][1:]:
                     # Don't replace inside templates (T266411)
-                    end = replaceExcept(end, re.escape(ref), repeated_ref,
-                                        exceptions=['template'])
+                    end = replaceExcept(end, re.escape(ref_match),
+                                        repeated_ref, exceptions=['template'])
                 text = header + end

         # Fix references with different names

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1360352?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I152664218cf36b80676040690946a0ba77b9a3ce
Gerrit-Change-Number: 1360352
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to