jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1195404?usp=email )
Change subject: doc: Update ROADMAP.rst
......................................................................
doc: Update ROADMAP.rst
Change-Id: If4cd839b84b7eeb8f15846a4984dc5550cc46fc3
---
M ROADMAP.rst
1 file changed, 5 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index e1a8b9e..46a13ea 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,7 +1,11 @@
Current Release Changes
=======================
-* Python 3.8 support will be discontinued and probably this is the last version supporting it.
+* Added :func:`tools.itertools.union_generators` for sorted merging of pre-sorted iterables.
+* **Support for Python 3.8 will be discontinued**;
+ this is likely the last Pywikibot version to support it.
+* Added a Citoid Query interface with the :mod:`data.citoid` module.
+* Updated localization (L10N) files.
* :meth:`Family.interwiki_replacements<family.Family.interwiki_replacements>` is deprecated;
use :attr:`Family.code_aliases<family.Family.code_aliases>` instead.
* The first parameter of :meth:`Transliterator.transliterate
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1195404?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: If4cd839b84b7eeb8f15846a4984dc5550cc46fc3
Gerrit-Change-Number: 1195404
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1191851?usp=email )
Change subject: [IMPR] add union_generators function to tools.itertools
......................................................................
[IMPR] add union_generators function to tools.itertools
This can be used to merge sorted generators like in pagereferences()
Change-Id: Ibc1c2ef362a0703717b3331afb10cc238b61c9c8
---
M pywikibot/tools/itertools.py
1 file changed, 55 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/itertools.py b/pywikibot/tools/itertools.py
index e5911ba..d802c56 100644
--- a/pywikibot/tools/itertools.py
+++ b/pywikibot/tools/itertools.py
@@ -4,19 +4,25 @@
in :mod:`backports`
"""
#
-# (C) Pywikibot team, 2008-2024
+# (C) Pywikibot team, 2008-2025
#
# Distributed under the terms of the MIT license.
#
from __future__ import annotations
import collections
+import heapq
import itertools
from contextlib import suppress
-from itertools import chain, zip_longest
from typing import Any
-from pywikibot.backports import Generator, batched
+from pywikibot.backports import (
+ Callable,
+ Generator,
+ Iterable,
+ Iterator,
+ batched,
+)
from pywikibot.logging import debug
from pywikibot.tools import deprecated
@@ -27,6 +33,7 @@
'islice_with_ellipsis',
'itergroup',
'roundrobin_generators',
+ 'union_generators',
)
@@ -90,6 +97,47 @@
yield marker
+def union_generators(*iterables: Iterable[Any],
+ key: Callable[[Any], Any] | None = None,
+ reverse: bool = False) -> Iterator[Any]:
+ """Generator of union of sorted iterables.
+
+ Yield all items from the input iterables in sorted order, removing
+ duplicates. The input iterables must already be sorted according to
+ the same *key* and direction. For descending direction, *reverse*
+ must be ``True``. The generator will yield each element only once,
+ even if it appears in multiple iterables. This behaves similarly to:
+
+ sorted(set(itertools.chain(*iterables)), key=key, reverse=reverse)
+
+ but is memory-efficient since it processes items lazily.
+
+ Sample:
+
+ >>> list(union_generators([1, 2, 3, 4], [3, 4, 5], [2, 6]))
+ [1, 2, 3, 4, 5, 6]
+ >>> list(union_generators([4, 3, 2, 1], [5, 4, 3], [6, 2], reverse=True))
+ [6, 5, 4, 3, 2, 1]
+
+ .. versionadded:: 10.6
+
+ .. note::
+ All input iterables must be sorted consistently. *reverse* must
+ be set to ``True`` only if the iterables are sorted in descending
+ order. For simple concatenation without duplicate removal, use
+ :pylib:`itertools.chain<itertools#itertools.chain>` instead.
+
+ :param iterables: Sorted iterables to merge.
+ :param key: Optional key function to compare elements. If ``None``,
+ items are compared directly.
+ :param reverse: Whether the input iterables are sorted in descending
+ order.
+ :return: Generator yielding all unique items in sorted order.
+ """
+ merged = heapq.merge(*iterables, key=key, reverse=reverse)
+ return (list(group)[0] for _, group in itertools.groupby(merged, key=key))
+
+
def intersect_generators(*iterables, allow_duplicates: bool = False):
"""Generator of intersect iterables.
@@ -155,7 +203,7 @@
# Get items from iterables in a round-robin way.
sentinel = object()
- for items in zip_longest(*iterables, fillvalue=sentinel):
+ for items in itertools.zip_longest(*iterables, fillvalue=sentinel):
for index, item in enumerate(items):
if item is sentinel:
@@ -184,7 +232,8 @@
# a subset of active iterables.
if len(active_iterables) < n_gen:
cached_iterables = set(
- chain.from_iterable(v.keys() for v in cache.values()))
+ itertools.chain.from_iterable(v.keys()
+ for v in cache.values()))
if cached_iterables <= active_iterables:
return
@@ -210,7 +259,7 @@
sentinel = object()
return (item
for item in itertools.chain.from_iterable(
- zip_longest(*iterables, fillvalue=sentinel))
+ itertools.zip_longest(*iterables, fillvalue=sentinel))
if item is not sentinel)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1191851?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: Ibc1c2ef362a0703717b3331afb10cc238b61c9c8
Gerrit-Change-Number: 1191851
Gerrit-PatchSet: 5
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>
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1195398?usp=email )
Change subject: Announcement:Show a warning if Pywikibot is running with Python 3.8
......................................................................
Announcement:Show a warning if Pywikibot is running with Python 3.8
Bug: T401802
Change-Id: I0edb2ded34360fa2739eb0c93bae393e1e2d6719
---
M ROADMAP.rst
M docs/index.rst
M pywikibot/__init__.py
M tests/utils.py
4 files changed, 18 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index be4cfa4..e1a8b9e 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,6 +1,7 @@
Current Release Changes
=======================
+* Python 3.8 support will be discontinued and probably this is the last version supporting it.
* :meth:`Family.interwiki_replacements<family.Family.interwiki_replacements>` is deprecated;
use :attr:`Family.code_aliases<family.Family.code_aliases>` instead.
* The first parameter of :meth:`Transliterator.transliterate
@@ -31,6 +32,7 @@
Pending removal in Pywikibot 11
-------------------------------
+* 10.6.0: Python 3.8 support is deprecated and will be dropped soon
* 8.4.0: :attr:`data.api.QueryGenerator.continuekey` will be removed in favour of
:attr:`data.api.QueryGenerator.modules`
* 8.4.0: The *modules_only_mode* parameter in the :class:`data.api.ParamInfo` class, its
diff --git a/docs/index.rst b/docs/index.rst
index 46b4fe6..1673cd2 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -21,7 +21,8 @@
whether you have Python installed and to find its version, just type
``python`` at the CMD or shell prompt.
-Python 3.8 or higher is currently required to run.
+Python 3.8 or higher is currently required to run the bot but Python 3.9 or
+higher is recommended. Python 3.8 support will be dropped with Pywikibot 11 soon.
Pywikibot and this documentation are licensed under the
:ref:`MIT license`;
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 9b35fde..4ddaf22 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -59,7 +59,7 @@
)
from pywikibot.site import BaseSite as _BaseSite
from pywikibot.time import Timestamp
-from pywikibot.tools import normalize_username
+from pywikibot.tools import PYTHON_VERSION, normalize_username
if TYPE_CHECKING:
@@ -87,6 +87,15 @@
_sites: dict[str, APISite] = {}
+if PYTHON_VERSION < (3, 9):
+ __version = sys.version.split(maxsplit=1)[0]
+ warnings.warn(f"""
+
+ Python {__version} will be dropped soon with Pywikibot 11.
+ It is recommended to use Python 3.9 or above.
+ See phab: T401802 for further information.
+""", FutureWarning) # adjust warnings.warn line no in utils.execute()
+
@cache
def _code_fam_from_url(url: str, name: str | None = None) -> tuple[str, str]:
diff --git a/tests/utils.py b/tests/utils.py
index cf5860f..870ca14 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -25,6 +25,7 @@
from pywikibot.exceptions import APIError
from pywikibot.login import LoginStatus
from pywikibot.site import Namespace
+from pywikibot.tools import PYTHON_VERSION
from pywikibot.tools.collections import EMPTY_DEFAULT
from tests import _pwb_py
@@ -474,6 +475,9 @@
:param command: executable to run and arguments to use
"""
+ if PYTHON_VERSION < (3, 9):
+ command.insert(1, '-W ignore::FutureWarning:pywikibot:92')
+
env = os.environ.copy()
# Prevent output by test package; e.g. 'max_retries reduced from x to y'
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1195398?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: I0edb2ded34360fa2739eb0c93bae393e1e2d6719
Gerrit-Change-Number: 1195398
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot