jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/610809 )
Change subject: [4.0] Remove Python 2 related code in exceptions.py ......................................................................
[4.0] Remove Python 2 related code in exceptions.py
Change-Id: I4f4558897376afdb98a57f24d2877eb9cb342ffc --- M pywikibot/exceptions.py 1 file changed, 15 insertions(+), 19 deletions(-)
Approvals: Zhuyifei1999: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py index 1a8cef3..9da1d8d 100644 --- a/pywikibot/exceptions.py +++ b/pywikibot/exceptions.py @@ -87,9 +87,7 @@ # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, division, unicode_literals - -from pywikibot.tools import UnicodeMixin, UnicodeType, _NotImplementedWarning +from pywikibot.tools import _NotImplementedWarning
class NotImplementedWarning(_NotImplementedWarning): @@ -113,17 +111,16 @@ pass
-class Error(UnicodeMixin, Exception): +class Error(Exception):
"""Pywikibot error."""
- # NOTE: UnicodeMixin must be the first object Error class is derived from. - def __init__(self, arg): + def __init__(self, arg: str): """Initializer.""" self.unicode = arg
- def __unicode__(self): - """Return a unicode string representation.""" + def __str__(self) -> str: + """Return a string representation.""" return self.unicode
@@ -159,10 +156,9 @@ self.site = page.site
if '%(' in self.message and ')s' in self.message: - super(PageRelatedError, self).__init__( - self.message % self.__dict__) + super().__init__(self.message % self.__dict__) else: - super(PageRelatedError, self).__init__(self.message % page) + super().__init__(self.message % page)
def getPage(self): """Return the page related to the exception.""" @@ -182,7 +178,7 @@ @property def args(self): """Expose args.""" - return UnicodeType(self) + return str(self)
class OtherPageSaveError(PageSaveRelatedError): @@ -198,12 +194,12 @@ @type reason: Exception or basestring """ self.reason = reason - super(OtherPageSaveError, self).__init__(page) + super().__init__(page)
@property def args(self): """Expose args.""" - return UnicodeType(self.reason) + return str(self.reason)
class NoUsername(Error): @@ -262,7 +258,7 @@
""" self.message = "Query on %s returned data on '{0}'".format(actual) - super(InconsistentTitleReceived, self).__init__(page) + super().__init__(page)
class SiteDefinitionError(Error): @@ -351,7 +347,7 @@ """ self.target_page = target_page self.target_site = target_page.site - super(InterwikiRedirectPage, self).__init__(page) + super().__init__(page)
class InvalidTitle(Error): @@ -454,7 +450,7 @@ def __init__(self, page, url): """Initializer.""" self.url = url - super(SpamblacklistError, self).__init__(page) + super().__init__(page)
class TitleblacklistError(PageSaveRelatedError): @@ -571,8 +567,8 @@ @param entity: Wikibase entity @type entity: WikibaseEntity """ - super(NoWikibaseEntity, self).__init__( - "Entity '%s' doesn't exist on %s" % (entity.id, entity.repo)) + super().__init__("Entity '%s' doesn't exist on %s" + % (entity.id, entity.repo)) self.entity = entity
pywikibot-commits@lists.wikimedia.org