jenkins-bot has submitted this change and it was merged.
Change subject: Enable flake8 hacking H501 rule
......................................................................
Enable flake8 hacking H501 rule
Prevents use of locals(), globals() and `__dict__`.
Where appropriate, #noqa is used to bypass this rule.
Change-Id: Icd939da458b5f0ede58d32dc3ccb23c78ee40992
---
M pywikibot/__init__.py
M pywikibot/config2.py
M pywikibot/data/api.py
M pywikibot/exceptions.py
M pywikibot/site.py
M pywikibot/throttle.py
M scripts/login.py
M scripts/transferbot.py
M tests/date_tests.py
M tox.ini
10 files changed, 23 insertions(+), 18 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 46bdfe7..812329f 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -603,7 +603,7 @@
tmp = __import__('pywikibot.site', fromlist=[interface])
interface = getattr(tmp, interface)
except ImportError:
- raise ValueError("Invalid interface name '%(interface)s'" %
locals())
+ raise ValueError('Invalid interface name: {0}'.format(interface))
if not issubclass(interface, BaseSite):
warning('Site called with interface=%s' % interface.__name__)
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 8fd624e..419e825 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -1097,7 +1097,7 @@
if _arg == "modified":
_all = 0
else:
- warning('Unknown arg %(_arg)s ignored' % locals())
+ warning('Unknown arg {0} ignored'.format(_arg))
_k = list(globals().keys())
_k.sort()
for _name in _k:
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index f161646..bf3c944 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -116,7 +116,7 @@
'{0}:{1}'.format(key, val)
for key, val in self.other.items()))
- return "%(code)s: %(info)s" % self.__dict__
+ return '{0}: {1}'.format(self.code, self.info)
class UploadWarning(APIError):
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 1d82980..f3624de 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -159,7 +159,8 @@
self.site = page.site
if '%(' in self.message and ')s' in self.message:
- super(PageRelatedError, self).__init__(self.message % self.__dict__)
+ super(PageRelatedError, self).__init__(
+ self.message % self.__dict__) # noqa: H501
else:
super(PageRelatedError, self).__init__(self.message % page)
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 5cfa43f..16d3e99 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1110,7 +1110,7 @@
# arbitrary stuff, then a wikilink. The wikilink may contain
# a label, although this is not useful.
return re.compile(r'\s*#%(pattern)s\s*:?\s*\[\[(.+?)(?:\|.*?)?\]\]'
- % locals(),
+ % {'pattern': pattern},
re.IGNORECASE | re.UNICODE | re.DOTALL)
def sametitle(self, title1, title2):
@@ -4714,7 +4714,7 @@
elif watch:
pywikibot.warning(
u"editpage: Invalid watch value '%(watch)s' ignored."
- % locals())
+ % {'watch': watch})
req = self._simple_request(**params)
while True:
try:
diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index 83e9f7e..d125df1 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -136,8 +136,9 @@
else:
f.close()
self.process_multiplicity = count
- pywikibot.log(u"Found %(count)s %(mysite)s processes "
- u"running, including this one." % locals())
+ pywikibot.log(
+ 'Found {0} {1} processes running, including this one.'.format(
+ count, mysite))
finally:
self.lock.release()
diff --git a/scripts/login.py b/scripts/login.py
index f156817..4350dc4 100755
--- a/scripts/login.py
+++ b/scripts/login.py
@@ -173,12 +173,14 @@
site.login(sysop)
user = site.user()
if user:
- pywikibot.output(u"Logged in on %(site)s as %(user)s." %
locals())
+ pywikibot.output(
+ 'Logged in on {0} as {1}.'.format(site, user))
else:
if logout:
- pywikibot.output(u"Logged out of %(site)s." %
locals())
+ pywikibot.output('Logged out of {0}.'.format(site))
else:
- pywikibot.output(u"Not logged in on %(site)s." %
locals())
+ pywikibot.output(
+ 'Not logged in on {0}.'.format(site))
except SiteDefinitionError:
pywikibot.output(u'%s.%s is not a valid site, please remove it'
u' from your config' % (lang, familyName))
diff --git a/scripts/transferbot.py b/scripts/transferbot.py
index 85a455b..4d996d2 100755
--- a/scripts/transferbot.py
+++ b/scripts/transferbot.py
@@ -133,7 +133,8 @@
Pages to transfer: %(gen_args)s
Prefix for transferred pages: %(prefix)s
- """ % locals())
+ """ % {'fromsite': fromsite, 'tosite': tosite,
+ 'gen_args': gen_args, 'prefix': prefix})
for page in gen:
summary = "Moved page from %s" % page.title(asLink=True)
diff --git a/tests/date_tests.py b/tests/date_tests.py
index c000332..822fc4c 100644
--- a/tests/date_tests.py
+++ b/tests/date_tests.py
@@ -37,15 +37,15 @@
for value in range(start, stop, step):
self.assertTrue(
predicate(value),
-
"date.formats['%(formatname)s']['%(code)s']:\n"
- "invalid value %(value)d" % locals())
+ "date.formats['%s']['%s']:\ninvalid
value %d"
+ % (formatname, code, value))
newValue = convFunc(convFunc(value))
self.assertEqual(
newValue, value,
-
"date.formats['%(formatname)s']['%(code)s']:\n"
- "value %(newValue)d does not match %(value)s"
- % locals())
+ "date.formats['%s']['%s']:\n"
+ "value %d does not match %s"
+ % (formatname, code, newValue, value))
return testMapEntry
for formatname in date.formats:
diff --git a/tox.ini b/tox.ini
index 554ec03..ceb05a7 100644
--- a/tox.ini
+++ b/tox.ini
@@ -243,7 +243,7 @@
-rdocs/requirements-py3.txt
[flake8]
-ignore =
E241,E402,E731,D105,D211,FI10,FI12,FI13,FI15,FI5,H101,H201,H202,H236,H237,H301,H306,H404,H405,H501,P102,P103
+ignore =
E241,E402,E731,D105,D211,FI10,FI12,FI13,FI15,FI5,H101,H201,H202,H236,H237,H301,H306,H404,H405,P102,P103
exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/*
max_line_length = 130
accept-encodings = utf-8
--
To view, visit
https://gerrit.wikimedia.org/r/237908
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icd939da458b5f0ede58d32dc3ccb23c78ee40992
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>