jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, but someone else must approve Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[bugfix] Remove deprecated exceptions

Deprecation warnings does not work for exceptions in Python 3.
Most of them are deprecated for more than 5 years. Python 3
fails for unknows reasons which is hard to figure out. It is
a better approach to get a clear exception message than a
ugly TypeError.

- remove exceptions_tests.py which tests exceptions
deprecations ony
- remove module wrapper exception entries in exceptions.py
and pywikibot/__init__.py
- remove unused imports
- adjust FutureWarning in utils.py

Bug: T253681
Change-Id: I76e6e247d43446832edbceeb6486579a6f50f212
---
M pywikibot/__init__.py
M pywikibot/exceptions.py
M tests/__init__.py
D tests/exceptions_tests.py
M tests/utils.py
5 files changed, 4 insertions(+), 166 deletions(-)

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index dd2b6ad..9dde2ad 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -32,7 +32,7 @@
QuitKeyboardInterrupt as _QuitKeyboardInterrupt,
)
from pywikibot import config2 as config
-from pywikibot.data.api import UploadWarning as _UploadWarning
+from pywikibot.data.api import UploadWarning
from pywikibot.diff import PatchManager
from pywikibot.exceptions import (
Error, InvalidTitle, BadTitle, NoPage, NoMoveTarget, SectionError,
@@ -47,8 +47,6 @@
CaptchaError, SpamblacklistError, TitleblacklistError,
CircularRedirect, InterwikiRedirectPage, WikiBaseError, NoWikibaseEntity,
CoordinateGlobeUnknownException,
- DeprecatedPageNotFoundError as _DeprecatedPageNotFoundError,
- _DeprecatedSpamfilterError, _EmailUserError,
)
from pywikibot.family import Family
from pywikibot.i18n import translate
@@ -108,8 +106,7 @@
'SpamblacklistError', 'stdout', 'TitleblacklistError', 'translate', 'ui',
'unicode2html', 'UnicodeMixin', 'UnknownExtension', 'UnknownFamily',
'UnknownSite', 'UnsupportedPage', 'UploadWarning', 'url2unicode', 'User',
- 'UserActionRefuse', 'UserBlocked', 'warning', 'WikiBaseError',
- 'WikidataBot',
+ 'UserBlocked', 'warning', 'WikiBaseError', 'WikidataBot',
)
__all__ += textlib_methods

@@ -1439,31 +1436,11 @@
'cookie_jar', replacement_name='pywikibot.comms.http.cookie_jar',
since='20150921')
wrapper._add_deprecated_attr(
- 'PageNotFound', _DeprecatedPageNotFoundError,
- warning_message=('{0}.{1} is deprecated, and no longer '
- 'used by pywikibot; use http.fetch() instead.'),
- since='20140924')
-wrapper._add_deprecated_attr(
- 'SpamfilterError', _DeprecatedSpamfilterError,
- warning_message='SpamfilterError is deprecated; '
- 'use SpamblacklistError instead.',
- since='20200405')
-wrapper._add_deprecated_attr(
- 'UserActionRefuse', _EmailUserError,
- warning_message='UserActionRefuse is deprecated; '
- 'use UserRightsError and/or NotEmailableError instead.',
- since='20141218')
-wrapper._add_deprecated_attr(
'QuitKeyboardInterrupt', _QuitKeyboardInterrupt,
warning_message='pywikibot.QuitKeyboardInterrupt is deprecated; '
'use pywikibot.bot.QuitKeyboardInterrupt instead.',
since='20150619')
wrapper._add_deprecated_attr(
- 'UploadWarning', _UploadWarning,
- warning_message='pywikibot.UploadWarning is deprecated; '
- 'use APISite.upload with a warning handler instead.',
- since='20150921')
-wrapper._add_deprecated_attr(
'MediaWikiVersion', _MediaWikiVersion,
warning_message='pywikibot.MediaWikiVersion is deprecated; '
'use pywikibot.tools.MediaWikiVersion instead.',
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index f5479e8..1a8cef3 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -89,14 +89,7 @@
#
from __future__ import absolute_import, division, unicode_literals

-from pywikibot.tools import (
- # __ to avoid conflict with ModuleDeprecationWrapper._deprecated
- deprecated as __deprecated,
- ModuleDeprecationWrapper as _ModuleDeprecationWrapper,
- UnicodeMixin,
- UnicodeType,
- _NotImplementedWarning,
-)
+from pywikibot.tools import UnicodeMixin, UnicodeType, _NotImplementedWarning


class NotImplementedWarning(_NotImplementedWarning):
@@ -609,50 +602,3 @@
"""Request failed with a maxlag timeout error."""

pass
-
-
-@__deprecated(since='20141214')
-class DeprecatedPageNotFoundError(Error):
-
- """Page not found (deprecated)."""
-
- pass
-
-
-@__deprecated(since='20141218')
-class _EmailUserError(UserRightsError, NotEmailableError):
-
- """Email related error."""
-
- pass
-
-
-@__deprecated(since='20200405')
-class _DeprecatedSpamfilterError(SpamblacklistError):
-
- """MediaWiki detected a blacklisted spam URL (deprecated)."""
-
- pass
-
-
-wrapper = _ModuleDeprecationWrapper(__name__)
-wrapper._add_deprecated_attr(
- 'UploadWarning',
- replacement_name='pywikibot.data.api.UploadWarning',
- warning_message='pywikibot.exceptions.UploadWarning is deprecated; '
- 'use APISite.upload with a warning handler instead.',
- since='20150921')
-wrapper._add_deprecated_attr('PageNotFound', DeprecatedPageNotFoundError,
- warning_message='{0}.{1} is deprecated, and no '
- 'longer used by pywikibot; use '
- 'http.fetch() instead.',
- since='20141214')
-wrapper._add_deprecated_attr('SpamfilterError', _DeprecatedSpamfilterError,
- warning_message='SpamfilterError is deprecated; '
- 'use SpamblacklistError instead.',
- since='20200405')
-wrapper._add_deprecated_attr(
- 'UserActionRefuse', _EmailUserError,
- warning_message='UserActionRefuse is deprecated; '
- 'use UserRightsError and/or NotEmailableError',
- since='20141218')
diff --git a/tests/__init__.py b/tests/__init__.py
index 6b00ec7..6402780 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -87,7 +87,6 @@
'edit',
'edit_failure',
'eventstreams',
- 'exceptions',
'family',
'file',
'fixes',
diff --git a/tests/exceptions_tests.py b/tests/exceptions_tests.py
deleted file mode 100644
index b205f38..0000000
--- a/tests/exceptions_tests.py
+++ /dev/null
@@ -1,84 +0,0 @@
-# -*- coding: utf-8 -*-
-"""Tests for exceptions."""
-#
-# (C) Pywikibot team, 2014-2018
-#
-# Distributed under the terms of the MIT license.
-#
-from __future__ import absolute_import, division, unicode_literals
-
-import pywikibot
-
-from tests.aspects import unittest, DeprecationTestCase
-
-
-class TestDeprecatedExceptions(DeprecationTestCase):
-
- """Test usage of deprecation in library code."""
-
- net = False
-
- def test_UploadWarning(self):
- """Test exceptions.UploadWarning is deprecated only."""
- # Accessing from the main package should be deprecated.
- cls = pywikibot.UploadWarning
-
- self.assertOneDeprecationParts('pywikibot.UploadWarning',
- 'APISite.upload with a warning handler')
-
- e = cls('foo', 'bar')
- self.assertIsInstance(e, pywikibot.Error)
- self.assertNoDeprecation()
-
- self._reset_messages()
-
- # And it should not be accessed from the exceptions module either.
- # The first access loads the symbol
- cls = pywikibot.exceptions.UploadWarning
-
- self.assertOneDeprecationParts('pywikibot.exceptions.UploadWarning',
- 'APISite.upload with a warning handler')
-
- e = cls('foo', 'bar')
- self.assertIsInstance(e, pywikibot.Error)
- self.assertNoDeprecation()
-
- # Check this again because the second time it should be cached
- cls = pywikibot.exceptions.UploadWarning
-
- self.assertOneDeprecationParts('pywikibot.exceptions.UploadWarning',
- 'APISite.upload with a warning handler')
-
- e = cls('foo', 'bar')
- self.assertIsInstance(e, pywikibot.Error)
- self.assertNoDeprecation()
-
- def test_PageNotFound(self):
- """Test PageNotFound is deprecated from the package."""
- cls = pywikibot.PageNotFound
- self.assertOneDeprecation(
- 'pywikibot.PageNotFound is deprecated, and no longer '
- 'used by pywikibot; use http.fetch() instead.')
-
- e = cls('foo')
- self.assertIsInstance(e, pywikibot.Error)
- self.assertOneDeprecationParts(
- 'pywikibot.exceptions.DeprecatedPageNotFoundError')
-
- cls = pywikibot.exceptions.PageNotFound
-
- self.assertOneDeprecation(
- 'pywikibot.exceptions.PageNotFound is deprecated, and no longer '
- 'used by pywikibot; use http.fetch() instead.')
-
- e = cls('foo')
- self.assertIsInstance(e, pywikibot.Error)
- self.assertOneDeprecationParts(
- 'pywikibot.exceptions.DeprecatedPageNotFoundError')
-
-
-if __name__ == '__main__': # pragma: no cover
- try:
- unittest.main()
- except SystemExit:
- pass
diff --git a/tests/utils.py b/tests/utils.py
index 89456be..d73ecb0 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -602,7 +602,7 @@
@type command: list of unicode
"""
if PY2 or PYTHON_VERSION < (3, 5, 0):
- command.insert(1, '-W ignore::FutureWarning:pywikibot:128')
+ command.insert(1, '-W ignore::FutureWarning:pywikibot:125')
if cryptography_version and cryptography_version < [1, 3, 4]:
command.insert(1, '-W ignore:Old version of cryptography:Warning')
# Any environment variables added on Windows must be of type

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I76e6e247d43446832edbceeb6486579a6f50f212
Gerrit-Change-Number: 598977
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)