jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1304862?usp=email )
Change subject: Remove special namespaces -1 and -2 if not: directive is used
with ns
......................................................................
Remove special namespaces -1 and -2 if not: directive is used with ns
If not: directive is used with -namespaces pagegenerators option exclude
special namespaces from the list of namespaces passed to the API.
Update documentation and tests.
Bug: T429803
Change-Id: I401938ae61ec363ac3acbac1ca973d4cc6a142f4
---
M pywikibot/pagegenerators/__init__.py
M pywikibot/pagegenerators/_factory.py
M tests/pagegenerators_tests.py
3 files changed, 27 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators/__init__.py
b/pywikibot/pagegenerators/__init__.py
index c46ea06..d866048 100644
--- a/pywikibot/pagegenerators/__init__.py
+++ b/pywikibot/pagegenerators/__init__.py
@@ -478,9 +478,11 @@
pages in total. If used with multiple generators,
pages are yielded in a roundrobin way.
--namespaces Filter the page generator to only yield pages in the
--namespace specified namespaces. Separate multiple namespace
--ns numbers or names with commas.
+-namespaces Aliases :kbd:`-namespace` and :kbd:`-ns`.
+
+ Filter the page generator to only yield pages in the
+ specified namespaces. Separate multiple namespace
+ numbers or names with commas.
Examples::
@@ -494,6 +496,11 @@
-ns:not:2,3
-ns:not:Help,File
+ .. versionchanged:: 11.5
+ When using the leading ``not`` directive, the special
+ namespaces ``-1`` and ``-2`` are not included. To
+ add them, specify them explicitly, e.g. ``-ns:-1``.
+
If used with -newpages/-random/-randomredirect/-linter
generators, -namespace/ns must be provided before
-newpages/-random/-randomredirect/-linter.
diff --git a/pywikibot/pagegenerators/_factory.py
b/pywikibot/pagegenerators/_factory.py
index 1b2c076..db1802a 100644
--- a/pywikibot/pagegenerators/_factory.py
+++ b/pywikibot/pagegenerators/_factory.py
@@ -654,7 +654,14 @@
return TextIOPageGenerator(value, site=self.site)
def _handle_namespaces(self, value: str) -> Literal[True]:
- """Handle `-namespaces` argument."""
+ """Handle `-namespaces` argument.
+
+ .. version-changed:: 11.5
+ If preleading ``not:`` directive is given, special namespaces
+ ``-1`` and ``-2`` are not included.
+
+ :meta public:
+ """
if isinstance(self._namespaces, frozenset):
raise RuntimeError('-namespace/ns option must be provided before '
'-newpages/-random/-randomredirect/-linter')
@@ -665,9 +672,10 @@
value = value.removeprefix(not_key)
resolve = self.site.namespaces.resolve
not_ns = set(resolve(value.split(',')))
+ special_ns = set(resolve([-1, -2]))
if not self._namespaces:
self._namespaces = list(
- set(self.site.namespaces.values()) - not_ns)
+ set(self.site.namespaces.values()) - not_ns - special_ns)
else:
self._namespaces = list(
set(resolve(self._namespaces)) - not_ns)
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 16239e1..b80710d 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -755,6 +755,9 @@
ns = set(range(16))
ns.remove(2)
self.assertTrue(ns.issubset(gf.namespaces))
+ self.assertNotIn(2, gf.namespaces)
+ self.assertNotIn(-1, gf.namespaces)
+ self.assertNotIn(-2, gf.namespaces)
def test_two_excluded_namespaces(self) -> None:
"""Test two excluded namespaces."""
@@ -765,6 +768,10 @@
ns.remove(2)
ns.remove(1)
self.assertTrue(ns.issubset(gf.namespaces))
+ self.assertNotIn(2, gf.namespaces)
+ self.assertNotIn(1, gf.namespaces)
+ self.assertNotIn(-1, gf.namespaces)
+ self.assertNotIn(-2, gf.namespaces)
def test_two_excluded_named_namespaces(self) -> None:
"""Test two excluded named namespaces."""
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1304862?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: I401938ae61ec363ac3acbac1ca973d4cc6a142f4
Gerrit-Change-Number: 1304862
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Ivan-r <[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]