jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1197040?usp=email )

Change subject: cleanup: deprecate old (type, value, traceback) signature in 
throw
......................................................................

cleanup: deprecate old (type, value, traceback) signature in throw

Deprecate old (type, value, traceback) signature in GeneratorWrapper.throw.
The old behaviour is necessary for Python 3.8.

Bug: T340641
Change-Id: I7c50327253ff3209d801b9be6f02082730238cfa
---
M pywikibot/tools/collections.py
1 file changed, 42 insertions(+), 3 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/tools/collections.py b/pywikibot/tools/collections.py
index 5ef1cb9..458c06b 100644
--- a/pywikibot/tools/collections.py
+++ b/pywikibot/tools/collections.py
@@ -1,6 +1,6 @@
 """Collections datatypes."""
 #
-# (C) Pywikibot team, 2014-2024
+# (C) Pywikibot team, 2014-2025
 #
 # Distributed under the terms of the MIT license.
 #
@@ -11,9 +11,16 @@
 from collections.abc import Collection, Generator, Iterator, Mapping
 from contextlib import suppress
 from itertools import chain
+from types import TracebackType
 from typing import Any, NamedTuple

 from pywikibot.backports import Generator as GeneratorType
+from pywikibot.exceptions import ArgumentDeprecationWarning
+from pywikibot.tools import (
+    PYTHON_VERSION,
+    deprecated_args,
+    issue_deprecation_warning,
+)


 __all__ = (
@@ -277,18 +284,50 @@
             self._started_gen = self.generator
         return next(self._started_gen)

-    def throw(self, typ: Exception, val=None, tb=None) -> None:
+    @deprecated_args(val='value', tb='traceback')  # since 10.7.0
+    def throw(self,
+              typ: BaseException | type[BaseException] | None = None,
+              value: Any = None,
+              traceback: TracebackType | None = None) -> None:
         """Raise an exception inside the wrapped generator.

         Refer :python:`generator.throw()
         <reference/expressions.html#generator.throw>` for various
         parameter usage.

+        .. versionchanged:: 10.7
+           The *val* and *tb* parameters were renamed to *value* and
+           *traceback*.
+        .. deprecated:: 10.7
+           The ``(type, value, traceback)`` signature is deprecated; use
+           single-arg signature ``throw(value)`` instead.
+
         :raises RuntimeError: No generator started
+        :raises TypeError: Invalid type for *typ* argument
         """
         if not hasattr(self, '_started_gen'):
             raise RuntimeError('No generator was started')
-        self._started_gen.throw(typ, val, tb)
+
+        # New-style (single exception instance) with keyword argument
+        if typ is None and traceback is None and isinstance(value,
+                                                            BaseException):
+            self._started_gen.throw(value)
+            return
+
+        if PYTHON_VERSION > (3, 8) and not (value is None
+                                            and traceback is None):
+            # Old-style (type, value, traceback) signature
+            issue_deprecation_warning(
+                'The (type, value, traceback) signature of throw()',
+                'the single-arg signature',
+                warning_class=ArgumentDeprecationWarning,
+                since='10.7.0'
+            )
+            self._started_gen.throw(typ, value, traceback)
+            return
+
+        # New-style (single exception instance)
+        self._started_gen.throw(typ)

     def restart(self) -> None:
         """Restart the generator."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1197040?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: I7c50327253ff3209d801b9be6f02082730238cfa
Gerrit-Change-Number: 1197040
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to