jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
cleanup: remove issue_deprecation_warning for APISite.allpages()

- remove issue_deprecation_warning for filterredir parameter of
APISite.allpages() and raise a TypeError if the parameter is invalid.
- deprecate includeredirects parameter of
pagegenerators.AllpagesPageGenerator and
pagegenerators.PrefixingPageGenerator; filterredir parameter should
be used instead.
- update tests

Change-Id: I5131bcbd89deed6545e4f886a66d587e228726b0
---
M ROADMAP.rst
M pywikibot/pagegenerators/_generators.py
M pywikibot/site/_generators.py
M tests/site_tests.py
4 files changed, 110 insertions(+), 84 deletions(-)

diff --git a/ROADMAP.rst b/ROADMAP.rst
index b7fc4c2..724ba87 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -11,6 +11,8 @@

**Breaking changes and code cleanups**

+* Values of :meth:`APISite.allpages()<pywikibot.site._generators.GeneratorsMixin.allpages>`
+ parameter filterredir must be True, False or None
* :mod:`tools.threading` classes no longer can be imported from :mod:`tools`
* :mod:`tools.itertools` datatypes no longer can be imported from :mod:`tools`
* :mod:`tools.collections` datatypes no longer can be imported from :mod:`tools`
@@ -26,6 +28,8 @@
Current Deprecations
====================

+* 10.0.0: *includeredirects* parameter of :func:`pagegenerators.AllpagesPageGenerator` and
+ :func:`pagegenerators.PrefixingPageGenerator` is deprecated and should be replaced by *filterredir*
* 10.0.0: *importlib_metadata* of :mod:`backports` is deprecated
* 9.6.0: :meth:`BaseSite.languages()<pywikibot.site._basesite.BaseSite.languages>` will be removed in favour of
:attr:`BaseSite.codes<pywikibot.site._basesite.BaseSite.codes>`
@@ -104,4 +108,3 @@
* 7.0.0: A boolean watch parameter in Page.save() is deprecated and will be desupported
* 7.0.0: baserevid parameter of editSource(), editQualifier(), removeClaims(), removeSources(), remove_qualifiers()
DataSite methods will be removed
-* 7.0.0: Values of APISite.allpages() parameter filterredir other than True, False and None are deprecated
diff --git a/pywikibot/pagegenerators/_generators.py b/pywikibot/pagegenerators/_generators.py
index ffe6752..a536928 100644
--- a/pywikibot/pagegenerators/_generators.py
+++ b/pywikibot/pagegenerators/_generators.py
@@ -11,6 +11,7 @@
import io
import re
import sys
+import typing
from collections import abc
from functools import partial
from http import HTTPStatus
@@ -32,7 +33,7 @@
from pywikibot.comms import http
from pywikibot.exceptions import APIError, ServerError
from pywikibot.site import Namespace
-from pywikibot.tools import deprecated
+from pywikibot.tools import deprecated, issue_deprecation_warning
from pywikibot.tools.collections import GeneratorWrapper
from pywikibot.tools.itertools import filter_unique

@@ -42,7 +43,6 @@
from pywikibot.site._namespace import SingleNamespaceType
from pywikibot.time import Timestamp

-
# This is the function that will be used to de-duplicate page iterators.
_filter_unique_pages = partial(
filter_unique, key=lambda page: '{}:{}:{}'.format(*page._cmpkey()))
@@ -51,51 +51,93 @@
def AllpagesPageGenerator(
start: str = '!',
namespace: SingleNamespaceType = 0,
- includeredirects: str | bool = True,
+ includeredirects: typing.Literal['only'] | bool = True,
site: BaseSite | None = None,
- total: int | None = None, content: bool = False
+ total: int | None = None,
+ content: bool = False,
+ *,
+ filterredir: bool | None = None,
) -> Iterable[pywikibot.page.Page]:
"""Iterate Page objects for all titles in a single namespace.

- If includeredirects is False, redirects are not included. If
- includeredirects equals the string 'only', only redirects are added.
+ .. deprecated:: 10.0
+ The *includeredirects* parameter; use *filterredir* instead.
+ .. seealso:: :meth:`APISite.allpages()
+ <pywikibot.site._generators.GeneratorsMixin.allpages>`

- :param total: Maximum number of pages to retrieve in total
- :param content: If True, load current version of each page (default False)
+ :param start: if provided, only generate pages >= this title
+ lexically
+ :param namespace: Namespace to retrieve pages from
+ :param includeredirects: If False, redirects are not included. If
+ equals the string 'only', only redirects are added. Otherwise
+ redirects will be included. This parameter is deprecated; use
+ *filterredir* instead.
:param site: Site for generator results.
+ :param total: Maximum number of pages to retrieve in total
+ :param content: If True, load current version of each page (default
+ False)
+ :param filterredir: if True, only yield redirects; if False (and
+ not None), only yield non-redirects (default: yield both).
+ :return: a generator that yields Page objects
+ :raises ValueError: *filterredir* as well as *includeredirects*
+ parameters were given. Use *filterredir* only.
"""
if site is None:
site = pywikibot.Site()

- filterredir: bool | None = None
- if not includeredirects:
- filterredir = False
- elif includeredirects == 'only':
- filterredir = True
+ if filterredir is not None and includeredirects is not True:
+ raise ValueError(
+ f'filterredir parameter ({filterredir}) is used together with '
+ f'outdated includeredirects parameter ({includeredirects}).'
+ )
+
+ # backward compatibility
+ if includeredirects is not True:
+ if not includeredirects:
+ filterredir = False
+ elif includeredirects == 'only':
+ filterredir = True
+
+ issue_deprecation_warning(
+ 'includeredirects parameter ({includeredirects})',
+ f'filterredir={filterredir}',
+ since='10.0.0'
+ )

return site.allpages(start=start, namespace=namespace,
filterredir=filterredir, total=total, content=content)


-def PrefixingPageGenerator(prefix: str,
- namespace: SingleNamespaceType | None = None,
- includeredirects: bool | str | None = True,
- site: BaseSite | None = None,
- total: int | None = None,
- content: bool = False
- ) -> Iterable[pywikibot.page.Page]:
+def PrefixingPageGenerator(
+ prefix: str,
+ namespace: SingleNamespaceType | None = None,
+ includeredirects: typing.Literal['only'] | bool = True,
+ site: BaseSite | None = None,
+ total: int | None = None,
+ content: bool = False,
+ *,
+ filterredir: bool | None = None,
+) -> Iterable[pywikibot.page.Page]:
"""Prefixed Page generator.

+ .. deprecated:: 10.0
+ The *includeredirects* parameter; use *filterredir* instead.
+
:param prefix: The prefix of the pages.
:param namespace: Namespace to retrieve pages from
- :param includeredirects: If includeredirects is None, False or an empty
- string, redirects will not be found. If includeredirects equals the
- string 'only', only redirects will be found. Otherwise redirects will
- be included.
+ :param includeredirects: If False, redirects are not included. If
+ equals the string 'only', only redirects are added. Otherwise
+ redirects will be included. This parameter is deprecated; use
+ *filterredir* instead.
:param site: Site for generator results.
:param total: Maximum number of pages to retrieve in total
- :param content: If True, load current version of each page (default False)
+ :param content: If True, load current version of each page (default
+ False)
+ :param filterredir: if True, only yield redirects; if False (and
+ not None), only yield non-redirects (default: yield both).
:return: a generator that yields Page objects
+ :raises ValueError: *filterredir* as well as *includeredirects*
+ parameters were given. Use *filterredir* only.
"""
if site is None:
site = pywikibot.Site()
@@ -105,11 +147,24 @@
namespace = prefixlink.namespace
title = prefixlink.title

- filterredir: bool | None = None
- if not includeredirects:
- filterredir = False
- elif includeredirects == 'only':
- filterredir = True
+ if filterredir is not None and includeredirects is not True:
+ raise ValueError(
+ f'filterredir parameter ({filterredir}) is used together with '
+ f'outdated includeredirects parameter ({includeredirects}).'
+ )
+
+ # backward compatibility
+ if includeredirects is not True:
+ if not includeredirects:
+ filterredir = False
+ elif includeredirects == 'only':
+ filterredir = True
+
+ issue_deprecation_warning(
+ 'includeredirects parameter ({includeredirects})',
+ f'filterredir={filterredir}',
+ since='10.0.0'
+ )

return site.allpages(prefix=title, namespace=namespace,
filterredir=filterredir, total=total, content=content)
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index 145430f..b4ff377 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -25,11 +25,7 @@
)
from pywikibot.site._decorators import need_right
from pywikibot.site._namespace import NamespaceArgType
-from pywikibot.tools import (
- deprecate_arg,
- is_ip_address,
- issue_deprecation_warning,
-)
+from pywikibot.tools import deprecate_arg, is_ip_address
from pywikibot.tools.itertools import filter_unique


@@ -950,40 +946,32 @@

:param start: Start at this title (page need not exist).
:param prefix: Only yield pages starting with this string.
- :param namespace: Iterate pages from this (single) namespace
- :param filterredir: if True, only yield redirects; if False (and not
- None), only yield non-redirects (default: yield both)
- :param filterlanglinks: if True, only yield pages with language links;
- if False (and not None), only yield pages without language links
- (default: yield both)
+ :param namespace: Iterate pages from this (single) namespace.
+ :param filterredir: if True, only yield redirects; if False (and
+ not None), only yield non-redirects (default: yield both).
+ :param filterlanglinks: if True, only yield pages with language
+ links; if False (and not None), only yield pages without
+ language links (default: yield both).
:param minsize: if present, only yield pages at least this many
- bytes in size
- :param maxsize: if present, only yield pages at most this many bytes
- in size
- :param protect_type: only yield pages that have a protection of the
- specified type
- :param protect_level: only yield pages that have protection at this
- level; can only be used if protect_type is specified
+ bytes in size.
+ :param maxsize: if present, only yield pages at most this many
+ bytes in size.
+ :param protect_type: only yield pages that have a protection of
+ the specified type.
+ :param protect_level: only yield pages that have protection at
+ this level; can only be used if protect_type is specified.
:param reverse: if True, iterate in reverse Unicode lexigraphic
- order (default: iterate in forward order)
- :param content: if True, load the current content of each iterated page
- (default False)
+ order (default: iterate in forward order).
+ :param content: if True, load the current content of each
+ iterated page (default False).
:raises KeyError: the namespace identifier was not resolved
:raises TypeError: the namespace identifier has an inappropriate
- type such as bool, or an iterable with more than one namespace
+ type such as bool, or an iterable with more than one
+ namespace or *filterredir* parameter has an invalid type.
"""
- # backward compatibility test
if filterredir not in (True, False, None):
- old = filterredir
- if not filterredir:
- filterredir = False
- elif filterredir == 'only':
- filterredir = True
- else:
- filterredir = None
- issue_deprecation_warning(
- f'The value "{old}" for "filterredir"',
- f'"{filterredir}"', since='7.0.0')
+ raise TypeError('filterredir parameter must be True, False or '
+ f'None, not {type(filterredir)}')

apgen = self._generator(api.PageGenerator, type_arg='allpages',
namespaces=namespace,
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 90301bf..e95633e 100755
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -36,26 +36,6 @@
from tests.basepage import BasePageLoadRevisionsCachingTestBase


-class TestSiteObjectDeprecatedFunctions(DefaultSiteTestCase,
- DeprecationTestCase):
-
- """Test cases for Site deprecated methods on a live wiki."""
-
- cached = True
-
- def test_allpages_filterredir_true(self):
- """Test that filterredir set to 'only' is deprecated to True."""
- for page in self.site.allpages(filterredir='only', total=1):
- self.assertTrue(page.isRedirectPage())
- self.assertOneDeprecation()
-
- def test_allpages_filterredir_talse(self):
- """Test if filterredir's bool is False it's deprecated to False."""
- for page in self.site.allpages(filterredir='', total=1):
- self.assertFalse(page.isRedirectPage())
- self.assertOneDeprecation()
-
-
class TestSiteObject(DefaultSiteTestCase):

"""Test cases for Site methods."""

To view, visit change 1100478. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5131bcbd89deed6545e4f886a66d587e228726b0
Gerrit-Change-Number: 1100478
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot