jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Adopt error message from Python 3.13 for batched function

Also add some doc tests

Change-Id: I97068d5dd664d125b53b870464ecb1fdc8bb4a65
---
M pywikibot/backports.py
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/pywikibot/backports.py b/pywikibot/backports.py
index e49e815..5286439 100644
--- a/pywikibot/backports.py
+++ b/pywikibot/backports.py
@@ -156,6 +156,14 @@
Traceback (most recent call last):
...
StopIteration
+ >>> list(batched('ABCD', 2))
+ [('A', 'B'), ('C', 'D')]
+ >>> list(batched('ABCD', 3, strict=False))
+ [('A', 'B', 'C'), ('D',)]
+ >>> list(batched('ABCD', 3, strict=True))
+ Traceback (most recent call last):
+ ...
+ ValueError: batched(): incomplete batch

.. seealso:: :python:`itertools.batched
<library/itertools.html#itertools.batched>`,
@@ -167,9 +175,9 @@
:param n: How many items of the iterable to get in one chunk
:param strict: raise a ValueError if the final batch is shorter
than *n*.
- :raise ValueError: the final batch is shorter than *n*.
+ :raise ValueError: batched(): incomplete batch
"""
- msg = f'The final batch is shorter than n={n}'
+ msg = 'batched(): incomplete batch'
if PYTHON_VERSION < (3, 12):
group = []
for item in iterable:

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

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