jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/894215 )
Change subject: [IMPR] Ignore talk pages with Site.watched_pages ......................................................................
[IMPR] Ignore talk pages with Site.watched_pages
- add new 'with_talkpage' parameter to Site.watched_pages - ignore talk pages and special pages is with_talkpage is False
Bug: T330806 Change-Id: Ifb3c90091e5d469950c45e593882b96885b8fc17 --- M pywikibot/site/_generators.py 1 file changed, 29 insertions(+), 1 deletion(-)
Approvals: Bináris: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py index cdb796a..4752b45 100644 --- a/pywikibot/site/_generators.py +++ b/pywikibot/site/_generators.py @@ -2113,21 +2113,36 @@ def watched_pages( self, force: bool = False, - total: Optional[int] = None + total: Optional[int] = None, *, + with_talkpage: bool = True ) -> Generator['pywikibot.Page', Any, None]: """Return watchlist.
.. note:: ``watched_pages`` is a restartable generator. See :class:`tools.collections.GeneratorWrapper` for its usage. .. seealso:: :api:`Watchlistraw` + .. versionadded:: 8.1 + the *with_talkpage* parameter.
:param force: Reload watchlist :param total: if not None, limit the generator to yielding this many items in total + :param with_talkpage: if false, ignore talk pages and special + pages :return: generator of pages in watchlist """ + def ignore_talkpages(page): + """Ignore talk pages and special pages.""" + ns = page.namespace() + return ns >= 0 and not page.namespace() % 2 + expiry = None if force else pywikibot.config.API_config_expiry gen = api.PageGenerator(site=self, generator='watchlistraw', expiry=expiry) gen.set_maximum_items(total) + + if not with_talkpage: + gen._namespaces = True + gen._check_result_namespace = ignore_talkpages + return gen
pywikibot-commits@lists.wikimedia.org