jenkins-bot merged this change.
[IMPR] derive LoginStatus from IntEnum
Removing name class method might be a breaking change
but I think this is never used elsewhere and can easily
replace by the IntEnum name attribute:
Instead LoginStatus.name(0) you may use LoginStatus(0).name
Bug: T213287
Change-Id: Id92f64671bde4c19463f516e1f273a8d33c67dcb
---
M pywikibot/site.py
1 file changed, 11 insertions(+), 19 deletions(-)
diff --git a/pywikibot/site.py b/pywikibot/site.py
index bd8d070..283133e 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -31,6 +31,7 @@
except ImportError: # Python 2.7
from collections import Iterable, Container, Mapping
from collections import namedtuple
+from enum import IntEnum
from warnings import warn
import pywikibot
@@ -101,18 +102,22 @@
"""Page cannot be reserved for writing due to existing lock."""
-class LoginStatus(object):
+class LoginStatus(IntEnum):
"""
Enum for Login statuses.
>>> LoginStatus.NOT_ATTEMPTED
- -3
- >>> LoginStatus.AS_USER
+ LoginStatus(-3)
+ >>> LoginStatus.IN_PROGRESS.value
+ -2
+ >>> LoginStatus.NOT_LOGGED_IN.name
+ NOT_LOGGED_IN
+ >>> int(LoginStatus.AS_USER)
0
- >>> LoginStatus.name(-3)
+ >>> LoginStatus(-3).name
'NOT_ATTEMPTED'
- >>> LoginStatus.name(0)
+ >>> LoginStatus(0).name
'AS_USER'
"""
@@ -122,22 +127,9 @@
AS_USER = 0
AS_SYSOP = 1
- @classmethod
- def name(cls, search_value):
- """Return the name of a LoginStatus by it's value."""
- for key, value in cls.__dict__.items():
- if key == key.upper() and value == search_value:
- return key
- raise KeyError('Value %r could not be found in this enum'
- % search_value)
-
- def __init__(self, state):
- """Initializer."""
- self.state = state
-
def __repr__(self):
"""Return internal representation."""
- return 'LoginStatus(%s)' % (LoginStatus.name(self.state))
+ return 'LoginStatus({})'.format(self)
Family = redirect_func(pywikibot.family.Family.load,
To view, visit change 538257. To unsubscribe, or for help writing mail filters, visit settings.