Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1240880?usp=email )
Change subject: pagegenerators: Support namespaces parameter for all category generators
......................................................................
pagegenerators: Support namespaces parameter for all category generators
- Add namespaces parameter to SubCategoriesPageGenerator
- use namespaces parameter in getCategoryGen which either calls
CategorizedPageGenerator or SubCategoriesPageGenerator.
This ensures that namespace filtering is applied consistently when using
any category option.
Inspired by T417961: using -catr together with -ns:0 now correctly
limits results to main namespace pages and avoids yielding FilePage
objects.
Bug: T417961
Change-Id: I54f9b1f67dbfa81cd7a6194add8686b37a492fa4
---
M pywikibot/pagegenerators/_factory.py
M pywikibot/pagegenerators/_generators.py
2 files changed, 44 insertions(+), 13 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/pagegenerators/_factory.py b/pywikibot/pagegenerators/_factory.py
index c9ed4b3..caacf4e 100644
--- a/pywikibot/pagegenerators/_factory.py
+++ b/pywikibot/pagegenerators/_factory.py
@@ -196,6 +196,11 @@
self.site.namespaces.resolve(self._namespaces))
return self._namespaces
+ @namespaces.deleter
+ def namespaces(self) -> None:
+ """Deleter of namespaces property."""
+ self._namespaces = frozenset()
+
def getCombinedGenerator(self, # noqa: N802
gen: OPT_GENERATOR_TYPE = None,
preload: bool = False) -> OPT_GENERATOR_TYPE:
@@ -346,6 +351,11 @@
gen_func: Callable | None = None) -> Any:
"""Return generator based on Category defined by category and gen_func.
+ .. versionchanged::11.1
+ *gen_func* is now called with the ``namespaces`` parameter
+ using the value from :attr:`namespaces`, because the namespace
+ option is prioritized in :meth:`handle_args`.
+
:param category: Category name with start parameter
:param recurse: If not False or 0, also iterate articles in
subcategories. If an int, limit recursion to this number of
@@ -359,10 +369,17 @@
cat, startfrom = self.getCategory(category)
- return gen_func(cat,
- start=startfrom,
- recurse=recurse,
- content=content)
+ ns = self.namespaces or None
+ # reset namespaces property to avoid filtering by getCombinedGenerator
+ del self.namespaces
+
+ return gen_func(
+ cat,
+ start=startfrom,
+ recurse=recurse,
+ content=content,
+ namespaces=ns
+ )
@staticmethod
def _parse_log_events(
diff --git a/pywikibot/pagegenerators/_generators.py b/pywikibot/pagegenerators/_generators.py
index 8ef461b..6edc8ed 100644
--- a/pywikibot/pagegenerators/_generators.py
+++ b/pywikibot/pagegenerators/_generators.py
@@ -338,6 +338,7 @@
) -> Generator[pywikibot.page.Page]:
"""Yield all pages in a specific category.
+ :param category: The Category object to generate subcategories from
:param recurse: If not False or 0, also iterate articles in
subcategories. If an int, limit recursion to this number of
levels, e.g. recurse=1 will iterate articles in first-level
@@ -348,6 +349,8 @@
all levels)
:param content: If True, retrieve the content of the current version
of each page (default False)
+ :param namespaces: List of namespaces to search in (default is None,
+ meaning all namespaces)
"""
yield from category.articles(
content=content,
@@ -358,14 +361,19 @@
)
-def SubCategoriesPageGenerator(category: pywikibot.page.Category,
- recurse: int | bool = False,
- start: str | None = None,
- total: int | None = None,
- content: bool = False,
- ) -> Generator[pywikibot.page.Page]:
+def SubCategoriesPageGenerator(
+ category: pywikibot.page.Category,
+ recurse: int | bool = False,
+ start: str | None = None,
+ total: int | None = None,
+ content: bool = False,
+ namespaces: NamespaceArgType = None,
+) -> Generator[pywikibot.page.Page]:
"""Yield all subcategories in a specific category.
+ .. versionchanged:: 11.1
+ *namespaces* parameter was added
+
:param category: The Category object to generate subcategories from
:param recurse: If not False or 0, also iterate articles in
subcategories. If an int, limit recursion to this number of
@@ -377,10 +385,16 @@
all levels)
:param content: If True, retrieve the content of the current version
of each page (default False)
+ :param namespaces: List of namespaces to search in (default is None,
+ meaning all namespaces)
"""
- return category.subcategories(recurse=recurse,
- total=total, content=content,
- startprefix=start)
+ return category.subcategories(
+ recurse=recurse,
+ total=total,
+ content=content,
+ startprefix=start,
+ namespaces=namespaces
+ )
def LinkedPageGenerator(
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1240880?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: I54f9b1f67dbfa81cd7a6194add8686b37a492fa4
Gerrit-Change-Number: 1240880
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1238707?usp=email )
Change subject: Move copyright headers above module docstrings
......................................................................
Move copyright headers above module docstrings
Bug: T416673
Change-Id: I43dacdab216d021eb24d01815c13c1a69baf9186
---
M pywikibot/logging.py
M pywikibot/plural.py
M pywikibot/scripts/generate_family_file.py
M pywikibot/site/_upload.py
M pywikibot/site_detect.py
M scripts/claimit.py
M scripts/delete.py
M scripts/maintenance/make_i18n_dict.py
M scripts/parser_function_count.py
M scripts/patrol.py
M tests/cache_tests.py
M tests/dry_api_tests.py
M tests/login_tests.py
M tests/pagegenerators_tests.py
M tests/textlib_tests.py
M tests/utils.py
M tests/xmlreader_tests.py
17 files changed, 58 insertions(+), 58 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/logging.py b/pywikibot/logging.py
index cd60dcb..c95a808 100644
--- a/pywikibot/logging.py
+++ b/pywikibot/logging.py
@@ -1,3 +1,8 @@
+#
+# (C) Pywikibot team, 2010-2026
+#
+# Distributed under the terms of the MIT license.
+#
"""User output/logging functions.
Six output functions are defined. Each requires a ``msg`` argument
@@ -23,11 +28,6 @@
- :pyhow:`Logging HOWTO<logging>`
- :python:`Logging Cookbook<howto/logging-cookbook.html>`
"""
-#
-# (C) Pywikibot team, 2010-2025
-#
-# Distributed under the terms of the MIT license.
-#
from __future__ import annotations
diff --git a/pywikibot/plural.py b/pywikibot/plural.py
index 081a454..289404f 100644
--- a/pywikibot/plural.py
+++ b/pywikibot/plural.py
@@ -1,9 +1,9 @@
-"""Module containing plural rules of various languages."""
#
-# (C) Pywikibot team, 2011-2025
+# (C) Pywikibot team, 2011-2026
#
# Distributed under the terms of the MIT license.
#
+"""Module containing plural rules of various languages."""
from __future__ import annotations
from typing import TYPE_CHECKING
diff --git a/pywikibot/scripts/generate_family_file.py b/pywikibot/scripts/generate_family_file.py
index 72c7d2c..ddf78a1 100755
--- a/pywikibot/scripts/generate_family_file.py
+++ b/pywikibot/scripts/generate_family_file.py
@@ -1,4 +1,9 @@
#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2010-2026
+#
+# Distributed under the terms of the MIT license.
+#
"""This script generates a family file from a given URL.
This script must be invoked with the pwb wrapper script/code entry point.
@@ -31,11 +36,6 @@
.. versionchanged:: 8.4
If the url scheme is missing, ``https`` will be used.
"""
-#
-# (C) Pywikibot team, 2010-2025
-#
-# Distributed under the terms of the MIT license.
-#
from __future__ import annotations
import re
diff --git a/pywikibot/site/_upload.py b/pywikibot/site/_upload.py
index 9ce19a1..8b2dbf3 100644
--- a/pywikibot/site/_upload.py
+++ b/pywikibot/site/_upload.py
@@ -1,9 +1,9 @@
-"""Objects representing API upload to MediaWiki sites."""
#
-# (C) Pywikibot team, 2009-2025
+# (C) Pywikibot team, 2009-2026
#
# Distributed under the terms of the MIT license.
#
+"""Objects representing API upload to MediaWiki sites."""
from __future__ import annotations
import mimetypes
diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py
index 97f59d3..70286dd 100644
--- a/pywikibot/site_detect.py
+++ b/pywikibot/site_detect.py
@@ -1,9 +1,9 @@
-"""Classes for detecting a MediaWiki site."""
#
-# (C) Pywikibot team, 2010-2025
+# (C) Pywikibot team, 2010-2026
#
# Distributed under the terms of the MIT license.
#
+"""Classes for detecting a MediaWiki site."""
from __future__ import annotations
import json
diff --git a/scripts/claimit.py b/scripts/claimit.py
index 2ed502f..413830e 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -1,4 +1,9 @@
#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2013-2026
+#
+# Distributed under the terms of the MIT license.
+#
"""A script that adds claims to Wikidata items based on a list of pages.
These command line parameters can be used to specify which pages to work on:
@@ -43,11 +48,6 @@
Note that the ordering of the letters in the 'exists' argument does not matter,
but 'p' must be included.
"""
-#
-# (C) Pywikibot team, 2013-2025
-#
-# Distributed under the terms of the MIT license.
-#
from __future__ import annotations
import pywikibot
diff --git a/scripts/delete.py b/scripts/delete.py
index b18e82f..0a82deb 100755
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -1,4 +1,9 @@
#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2013-2026
+#
+# Distributed under the terms of the MIT license.
+#
"""This script can be used to delete and undelete pages en masse.
Of course, you will need an admin account on the relevant wiki.
@@ -51,11 +56,6 @@
python pwb.py delete -cat:"To delete" -always
"""
-#
-# (C) Pywikibot team, 2013-2025
-#
-# Distributed under the terms of the MIT license.
-#
from __future__ import annotations
import collections
diff --git a/scripts/maintenance/make_i18n_dict.py b/scripts/maintenance/make_i18n_dict.py
index 1a1ae26..701caba 100755
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -1,4 +1,9 @@
#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2013-2026
+#
+# Distributed under the terms of the MIT license.
+#
"""Generate an i18n file from a given script.
Run IDLE at topmost level:
@@ -29,11 +34,6 @@
>>> bot.to_json()
"""
-#
-# (C) Pywikibot team, 2013-2025
-#
-# Distributed under the terms of the MIT license.
-#
from __future__ import annotations
import json
diff --git a/scripts/parser_function_count.py b/scripts/parser_function_count.py
index 60c02ed..6c74556 100755
--- a/scripts/parser_function_count.py
+++ b/scripts/parser_function_count.py
@@ -1,4 +1,9 @@
#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2013-2026
+#
+# Distributed under the terms of the MIT license.
+#
"""Used to find expensive templates that are subject to be converted to Lua.
It counts parser functions and then orders templates by number of these
@@ -42,11 +47,6 @@
Should you specify neither first nor atleast, all templates using parser
functions will be listed.
"""
-#
-# (C) Pywikibot team, 2013-2025
-#
-# Distributed under the terms of the MIT license.
-#
from __future__ import annotations
import re
diff --git a/scripts/patrol.py b/scripts/patrol.py
index c699385..ced9a77 100755
--- a/scripts/patrol.py
+++ b/scripts/patrol.py
@@ -1,4 +1,9 @@
#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2011-2026
+#
+# Distributed under the terms of the MIT license.
+#
"""The bot is meant to mark the edits based on info obtained by whitelist.
This bot obtains a list of recent changes and newpages and marks the
@@ -39,11 +44,6 @@
(default for any project except Wikipedia Projects)
-usercontribs Filter generators above to the given user
"""
-#
-# (C) Pywikibot team, 2011-2025
-#
-# Distributed under the terms of the MIT license.
-#
from __future__ import annotations
import time
diff --git a/tests/cache_tests.py b/tests/cache_tests.py
index d9671e1..7b0d959 100755
--- a/tests/cache_tests.py
+++ b/tests/cache_tests.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
-"""API Request cache tests."""
#
-# (C) Pywikibot team, 2012-2025
+# (C) Pywikibot team, 2012-2026
#
# Distributed under the terms of the MIT license.
#
+"""API Request cache tests."""
from __future__ import annotations
import re
diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py
index 3f5520b..3f0b19d 100755
--- a/tests/dry_api_tests.py
+++ b/tests/dry_api_tests.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
-"""API tests which do not interact with a site."""
#
-# (C) Pywikibot team, 2012-2025
+# (C) Pywikibot team, 2012-2026
#
# Distributed under the terms of the MIT license.
#
+"""API tests which do not interact with a site."""
from __future__ import annotations
import datetime
diff --git a/tests/login_tests.py b/tests/login_tests.py
index d2cdc29..8c85b20 100755
--- a/tests/login_tests.py
+++ b/tests/login_tests.py
@@ -1,13 +1,13 @@
#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2012-2026
+#
+# Distributed under the terms of the MIT license.
+#
"""Tests for LoginManager classes.
e.g. used to test password-file based login.
"""
-#
-# (C) Pywikibot team, 2012-2025
-#
-# Distributed under the terms of the MIT license.
-#
from __future__ import annotations
import builtins
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 2cf9661..f4985db 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
-"""Test pagegenerators module."""
#
-# (C) Pywikibot team, 2009-2025
+# (C) Pywikibot team, 2009-2026
#
# Distributed under the terms of the MIT license.
+"""Test pagegenerators module."""
from __future__ import annotations
import calendar
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 0bb7daa..d6af780 100755
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
-"""Test textlib module."""
#
-# (C) Pywikibot team, 2011-2025
+# (C) Pywikibot team, 2011-2026
#
# Distributed under the terms of the MIT license.
#
+"""Test textlib module."""
from __future__ import annotations
import functools
diff --git a/tests/utils.py b/tests/utils.py
index afe9743..318740d 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -1,9 +1,9 @@
-"""Test utilities."""
#
-# (C) Pywikibot team, 2013-2025
+# (C) Pywikibot team, 2013-2026
#
# Distributed under the terms of the MIT license.
#
+"""Test utilities."""
from __future__ import annotations
import inspect
diff --git a/tests/xmlreader_tests.py b/tests/xmlreader_tests.py
index c53afdc..dfd7e63 100755
--- a/tests/xmlreader_tests.py
+++ b/tests/xmlreader_tests.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
-"""Tests for xmlreader module."""
#
-# (C) Pywikibot team, 2009-2025
+# (C) Pywikibot team, 2009-2026
#
# Distributed under the terms of the MIT license.
#
+"""Tests for xmlreader module."""
from __future__ import annotations
import unittest
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1238707?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: I43dacdab216d021eb24d01815c13c1a69baf9186
Gerrit-Change-Number: 1238707
Gerrit-PatchSet: 9
Gerrit-Owner: Stitipragyan barik <stitipragyanbarik(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot