jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/751400 )
Change subject: [IMPR] Synchronize Page.linkedPages with Site.pagelinks ......................................................................
[IMPR] Synchronize Page.linkedPages with Site.pagelinks
- deprecate positional parameters in linkedPages but enable follow_redirect parameter
Change-Id: I66320602b0760097a2acd81ba06cf8ff8269c2bd --- M pywikibot/page/__init__.py M pywikibot/site/_generators.py 2 files changed, 54 insertions(+), 25 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index 903d7c0..fa76eba 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -11,7 +11,7 @@
""" # -# (C) Pywikibot team, 2008-2021 +# (C) Pywikibot team, 2008-2022 # # Distributed under the terms of the MIT license. # @@ -31,7 +31,7 @@
import pywikibot from pywikibot import config, i18n, textlib -from pywikibot.backports import Dict, Iterable, List, Tuple +from pywikibot.backports import Dict, Generator, Iterable, List, Tuple from pywikibot.comms import http from pywikibot.exceptions import ( APIError, @@ -1363,27 +1363,51 @@ else: raise NoPageError(self)
- def linkedPages(self, namespaces=None, - total: Optional[int] = None, - content: bool = False): - """ - Iterate Pages that this Page links to. + def linkedPages( + self, *args, **kwargs + ) -> Generator['pywikibot.Page', None, None]: + """Iterate Pages that this Page links to.
- Only returns pages from "normal" internal links. Image and category - links are omitted unless prefixed with ":". Embedded templates are - omitted (but links within them are returned). All interwiki and - external links are omitted. + Only returns pages from "normal" internal links. Embedded + templates are omitted but links within them are returned. All + interwiki and external links are omitted.
- :param namespaces: only iterate links in these namespaces - :param namespaces: int, or list of ints - :param total: iterate no more than this number of pages in total - :param content: if True, retrieve the content of the current version - of each linked page (default False) - :return: a generator that yields Page objects. - :rtype: generator + For the parameters refer + :py:mod:`APISite.pagelinks<pywikibot.site.APISite.pagelinks>` + + .. versionadded:: 7.0.0 + the `follow_redirects` keyword argument + .. deprecated:: 7.0.0 + the positional arguments + + .. seealso:: https://www.mediawiki.org/wiki/API:Links + + :keyword namespaces: Only iterate pages in these namespaces + (default: all) + :type namespaces: iterable of str or Namespace key, + or a single instance of those types. May be a '|' separated + list of namespace identifiers. + :keyword follow_redirects: if True, yields the target of any redirects, + rather than the redirect page + :keyword total: iterate no more than this number of pages in total + :keyword content: if True, load the current content of each page """ - return self.site.pagelinks(self, namespaces=namespaces, - total=total, content=content) + # Deprecate positional arguments and synchronize with Site.pagelinks + keys = ('namespaces', 'total', 'content') + for i, arg in enumerate(args): + key = keys[i] + issue_deprecation_warning( + 'Positional argument {} ({})'.format(i + 1, arg), + 'keyword argument "{}={}"'.format(key, arg), + since='7.0.0') + if key in kwargs: + pywikibot.warning('{!r} is given as keyword argument {!r} ' + 'already; ignoring {!r}' + .format(key, arg, kwargs[key])) + else: + kwargs[key] = arg + + return self.site.pagelinks(self, **kwargs)
def interwiki(self, expand=True): """ diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py index d40a54c..d3b8e65 100644 --- a/pywikibot/site/_generators.py +++ b/pywikibot/site/_generators.py @@ -14,7 +14,7 @@
import pywikibot import pywikibot.family -from pywikibot.backports import Dict, Iterable, List +from pywikibot.backports import Dict, Generator, Iterable, List from pywikibot.data import api from pywikibot.exceptions import ( APIError, @@ -360,11 +360,16 @@ namespaces=namespaces, content=content) ), total)
- def pagelinks(self, page, *, namespaces=None, follow_redirects=False, - total=None, content=False): + def pagelinks( + self, page, *, + namespaces=None, + follow_redirects: bool = False, + total: Optional[int] = None, + content: bool = False + ) -> Generator['pywikibot.Page', None, None]: """Iterate internal wikilinks contained (or transcluded) on page.
- :see: https://www.mediawiki.org/wiki/API:Links + .. seealso:: https://www.mediawiki.org/wiki/API:Links
:param namespaces: Only iterate pages in these namespaces (default: all) @@ -373,8 +378,8 @@ list of namespace identifiers. :param follow_redirects: if True, yields the target of any redirects, rather than the redirect page + :param total: iterate no more than this number of pages in total :param content: if True, load the current content of each iterated page - (default False) :raises KeyError: a namespace identifier was not resolved :raises TypeError: a namespace identifier has an inappropriate type such as NoneType or bool
pywikibot-commits@lists.wikimedia.org