jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/607865 )
Change subject: [IMPR] use 'isinstance' in favour of 'is type()' ......................................................................
[IMPR] use 'isinstance' in favour of 'is type()'
Due to PEP 8 object type comparisons should always use isinstance() instead of comparing types directly. https://www.python.org/dev/peps/pep-0008/#programming-recommendations
Change-Id: I3f493c18aa3ef873727f3fc7427dc2adcb8d519d --- M pywikibot/date.py M pywikibot/login.py M pywikibot/textlib.py 3 files changed, 5 insertions(+), 5 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py index c4e0030..9c97756 100644 --- a/pywikibot/date.py +++ b/pywikibot/date.py @@ -355,8 +355,6 @@ # A map of sitecode+pattern to (re matching object and corresponding decoders) _escPtrnCache2 = {}
-_listTypes = [list, tuple] -
def escapePattern2(pattern): """ @@ -464,7 +462,7 @@
params = encf(value)
- if type(params) in _listTypes: + if isinstance(params, (tuple, list)): assert len(params) == len(decoders), ( 'parameter count ({0}) does not match decoder count ({1})' .format(len(params), len(decoders))) diff --git a/pywikibot/login.py b/pywikibot/login.py index 04b74c8..d9d5484 100644 --- a/pywikibot/login.py +++ b/pywikibot/login.py @@ -232,10 +232,12 @@ entry = eval(line) except SyntaxError: entry = None - if type(entry) is not tuple: + + if not isinstance(entry, tuple): warn('Invalid tuple in line {0}'.format(line_nr), _PasswordFileWarning) continue + if not 2 <= len(entry) <= 4: warn('The length of tuple in line {0} should be 2 to 4 ({1} ' 'given)'.format(line_nr, entry), _PasswordFileWarning) diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index b4e7f36..5339249 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -316,7 +316,7 @@ # assume the string is a reference to a standard regex above, # which may not yet have a site specific re compiled. if exc in _regex_cache: - if type(_regex_cache[exc]) is tuple: + if isinstance(_regex_cache[exc], tuple): if not site and exc in ('interwiki', 'property', 'invoke', 'category', 'file'): issue_deprecation_warning(
pywikibot-commits@lists.wikimedia.org