jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1328699?usp=email )

Change subject: Use namespace name index in resolve
......................................................................

Use namespace name index in resolve

NamespacesDict already maintains a normalized name index for lookup_name.

Reuse it in resolve and remove the obsolete linear helper.

This makes named resolution consistent with other namespace lookups and avoids 
repeated scans.

Change-Id: Ibc6295dfa940a4c67b60965edb3e967b5d18fe13
---
M pywikibot/site/_namespace.py
M tests/namespace_tests.py
2 files changed, 10 insertions(+), 13 deletions(-)

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




diff --git a/pywikibot/site/_namespace.py b/pywikibot/site/_namespace.py
index f4fc547..447e055 100644
--- a/pywikibot/site/_namespace.py
+++ b/pywikibot/site/_namespace.py
@@ -444,7 +444,7 @@
         # int(None) raises TypeError; however, bool needs special handling.
         namespaces = self._namespaces
         result = [NotImplemented if isinstance(ns, bool)
-                  else self._lookup_name(ns)
+                  else self.lookup_name(ns)
                   if isinstance(ns, str) and not ns.lstrip('-').isdigit()
                   else namespaces.get(int(ns))
                   for ns in identifiers]
@@ -463,15 +463,3 @@
                                  if ns is None)))

         return result
-
-    def _lookup_name(self, name):
-        name = Namespace.normalize_name(name)
-        if name is False:
-            return None
-        name = name.lower()
-
-        for namespace in self._namespaces.values():
-            if namespace._contains_lowercase_name(name):
-                return namespace
-
-        return None
diff --git a/tests/namespace_tests.py b/tests/namespace_tests.py
index 28e1d3b..7fc2f77 100755
--- a/tests/namespace_tests.py
+++ b/tests/namespace_tests.py
@@ -285,6 +285,15 @@
                     # test __getitem__
                     self.assertEqual(self.namespaces[name].id, ns_id)

+    def test_resolve(self) -> None:
+        """Test resolving namespace names."""
+        for ns_id, values in self.tests.items():
+            with self.subTest(ns_id=ns_id):
+                self.assertEqual(
+                    self.namespaces.resolve(values),
+                    [self.namespaces[ns_id]] * len(values),
+                )
+
     def test_getattr(self) -> None:
         """Test NamespacesDict.__getattr__."""
         for ns_id, values in self.tests.items():

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1328699?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: Ibc6295dfa940a4c67b60965edb3e967b5d18fe13
Gerrit-Change-Number: 1328699
Gerrit-PatchSet: 2
Gerrit-Owner: 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