Xqt has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1237638?usp=email )
Change subject: Revert "[exceptions] Backport Exception.add_note() for Python <
3.11"
......................................................................
Revert "[exceptions] Backport Exception.add_note() for Python < 3.11"
This reverts commit 322e3dea227e9a8dc576a2747522e19796a3e40e.
Reason for revert: On hold. See comment on T416700
Bug: T416566
Change-Id: Ic5c49bc6b1a8c4e60186c05868cc76904d9aea51
---
M pywikibot/backports.py
M pywikibot/exceptions.py
M tests/__init__.py
D tests/exceptions_tests.py
4 files changed, 2 insertions(+), 85 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/backports.py b/pywikibot/backports.py
index 56d8bb6..d8b99d2 100644
--- a/pywikibot/backports.py
+++ b/pywikibot/backports.py
@@ -202,33 +202,3 @@
else:
from threading import RLock # type: ignore[assignment]
-
-
-# gh-100588
-if PYTHON_VERSION < (3, 11) or SPHINX_RUNNING:
- class BaseError(Exception):
-
- """Backport for Python 3.11 Exception.add_note logic."""
-
- def __init__(self, *args, **kwargs) -> None:
- """Initializer."""
- super().__init__(*args, **kwargs)
- self.__notes__: list = []
-
- def add_note(self, note: str) -> None:
- """Add a note to the exception."""
- if not isinstance(note, str):
- raise TypeError(
- f"note must be a str, not '{type(note).__name__}'")
- self.__notes__.append(note)
-
- def __str__(self) -> str:
- """Return string representation including notes."""
- s = super().__str__()
- if self.__notes__:
- return f'{s}\n' + '\n'.join(self.__notes__)
- return s
-else:
- class BaseError(Exception): # type: ignore[no-redef]
-
- """BaseError alias for Python 3.11+."""
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 26aae4d..ac14c12 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -172,7 +172,7 @@
instead.
"""
#
-# (C) Pywikibot team, 2008-2026
+# (C) Pywikibot team, 2008-2025
#
# Distributed under the terms of the MIT license.
#
@@ -182,8 +182,6 @@
from typing import Any
import pywikibot
-from pywikibot.backports import BaseError as _BaseError
-from pywikibot.tools import PYTHON_VERSION
from pywikibot.tools._deprecate import _NotImplementedWarning
@@ -202,23 +200,16 @@
"""Family class is missing definitions."""
-class Error(_BaseError):
+class Error(Exception):
"""Pywikibot error."""
def __init__(self, arg: Exception | str) -> None:
"""Initializer."""
- super().__init__(arg)
self.unicode = str(arg)
def __str__(self) -> str:
"""Return a string representation."""
- # On Python < 3.11, we must manually append notes because this method
- # overrides the BaseError.__str__ backport logic.
- if PYTHON_VERSION < (3, 11) and hasattr(self, '__notes__') \
- and self.__notes__:
- return self.unicode + '\n' + '\n'.join(self.__notes__)
-
return self.unicode
diff --git a/tests/__init__.py b/tests/__init__.py
index ee4966b..1a12448 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -83,7 +83,6 @@
'edit',
'edit_failure',
'eventstreams',
- 'exceptions',
'family',
'file',
'fixes',
diff --git a/tests/exceptions_tests.py b/tests/exceptions_tests.py
deleted file mode 100755
index 07a83ed..0000000
--- a/tests/exceptions_tests.py
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env python3
-"""Tests for exceptions."""
-#
-# (C) Pywikibot team, 2026
-#
-# Distributed under the terms of the MIT license.
-#
-from __future__ import annotations
-
-from pywikibot.exceptions import Error
-from pywikibot.tools import PYTHON_VERSION
-from tests.aspects import TestCase
-
-
-class TestExceptionAddNote(TestCase):
-
- """Test Error.add_note() backport logic."""
-
- net = False
-
- def test_add_note(self):
- """Test that add_note appends text to the exception string."""
- e = Error('Original Message')
- e.add_note('Note 1')
- e.add_note('Note 2')
-
- # Check that notes are stored internally (all versions)
- # In Py3.11+ this is native; in <3.11 it is our backport.
- self.assertTrue(hasattr(e, '__notes__'))
- self.assertEqual(e.__notes__, ['Note 1', 'Note 2'])
-
- # Check string representation
- # Case A: Python < 3.11 (Backport)
- # We expect the note to be baked into str(e)
- if PYTHON_VERSION < (3, 11):
- expected = 'Original Message\nNote 1\nNote 2'
- self.assertEqual(str(e), expected)
-
- # Case B: Python 3.11+ (Native)
- # We expect str(e) to ONLY be the message.
- # The traceback printer handles the notes separately.
- else:
- self.assertEqual(str(e), 'Original Message')
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1237638?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: Ic5c49bc6b1a8c4e60186c05868cc76904d9aea51
Gerrit-Change-Number: 1237638
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Anotida Expected <[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]