Xqt has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/395696 )
Change subject: [IMPR] code cleanup
......................................................................
[IMPR] code cleanup
- remove obsolete pass statements
- fix dicstring in imageuncat.py
- use context manager to open a file in solve_disambiguation.py
Change-Id: I5d0c862a9cdb11ce4bd12d9d68b397b19c62d602
---
M pywikibot/date.py
M pywikibot/page.py
M pywikibot/throttle.py
M scripts/cfd.py
M scripts/imageuncat.py
M scripts/makecat.py
M scripts/redirect.py
M scripts/solve_disambiguation.py
M scripts/upload.py
M scripts/welcome.py
M tests/aspects.py
M tests/ui_tests.py
12 files changed, 20 insertions(+), 40 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/96/395696/1
diff --git a/pywikibot/date.py b/pywikibot/date.py
index a9b0e39..f3ec6fb 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -7,7 +7,7 @@
# (C) Andre Engels, 2004-2005
# (C) Yuri Astrakhan, 2005-2006 (<Firstname><Lastname>@gmail.com)
# (years/decades/centuries/millenniums str <=> int conversions)
-# (C) Pywikibot team, 2004-2016
+# (C) Pywikibot team, 2004-2017
#
# Distributed under the terms of the MIT license.
#
@@ -377,10 +377,10 @@
decoders = []
for s in _reParameters.split(pattern):
if s is None:
- pass
- elif (len(s) in (2, 3) and s[0] == '%' and
- s[-1] in _digitDecoders and
- (len(s) == 2 or s[1] in _decimalDigits)):
+ continue
+ if (len(s) in (2, 3) and s[0] == '%' and
+ s[-1] in _digitDecoders and
+ (len(s) == 2 or s[1] in _decimalDigits)):
# Must match a "%2d" or "%d" style
dec = _digitDecoders[s[-1]]
if isinstance(dec, basestring):
diff --git a/pywikibot/page.py b/pywikibot/page.py
index ad87584..d9580b6 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -5978,6 +5978,5 @@
except UnicodeError as ex:
if not firstException:
firstException = ex
- pass
# Couldn't convert, raise the original exception
raise firstException
diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index 71c0da8..0f82b68 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -89,9 +89,7 @@
try:
f = open(self.ctrlfilename, 'r')
except IOError:
- if not pid:
- pass
- else:
+ if pid:
raise
else:
now = time.time()
diff --git a/scripts/cfd.py b/scripts/cfd.py
index b09db1f..7a56747 100755
--- a/scripts/cfd.py
+++ b/scripts/cfd.py
@@ -178,11 +178,7 @@
robot = CategoryMoveBot(oldcat=src, batch=True, comment=summary,
deletion_comment=action_summary,
inplace=True)
- else:
- # This line does not fit any of our regular expressions,
- # so ignore it.
- pass
- if summary != "" and robot is not None:
+ if summary and robot is not None:
pywikibot.stdout(summary)
# Run, robot, run!
robot.run()
diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py
index 315f839..f285299 100755
--- a/scripts/imageuncat.py
+++ b/scripts/imageuncat.py
@@ -1294,7 +1294,7 @@
Add the uncat template to the page.
@param page: Page to be modified
- @rtype: Page
+ @type page: pywikibot.Page
"""
newtext = page.get() + puttext
pywikibot.showDiff(page.get(), newtext)
diff --git a/scripts/makecat.py b/scripts/makecat.py
index c4c6f1b..0f647ad 100755
--- a/scripts/makecat.py
+++ b/scripts/makecat.py
@@ -79,7 +79,6 @@
pass
except pywikibot.IsRedirectPage:
cl = True
- pass
else:
cats = [x for x in pl.categories()]
if workingcat not in cats:
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 4ce593a..4fd4448 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -291,7 +291,6 @@
pass
except KeyError:
result = None
- pass
yield (redirect, result, target, final)
def retrieve_broken_redirects(self):
@@ -513,10 +512,8 @@
pywikibot.warning(
u'Redirect target %s is not a valid page title.'
% str(e)[10:])
- pass
except pywikibot.InvalidTitle:
pywikibot.exception()
- pass
except pywikibot.NoPage:
movedTarget = None
try:
@@ -611,8 +608,7 @@
u'Skipping: Redirect target %s is not a redirect.'
% newRedir.title(asLink=True))
break # do nothing
- else:
- pass # target found
+ # else target found
except pywikibot.SectionError:
pywikibot.warning(
u"Redirect target section %s doesn't exist."
@@ -683,7 +679,6 @@
if targetPage.isStaticRedirect():
pywikibot.output(
u" Redirect target is STATICREDIRECT.")
- pass
else:
newRedir = targetPage
continue
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index eb1b361..bdb9f07 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -462,15 +462,14 @@
try:
# The file is stored in the disambiguation/ subdir.
# Create if necessary.
- f = codecs.open(filename, 'r', 'utf-8')
- for line in f.readlines():
- # remove trailing newlines and carriage returns
- while line[-1] in ['\n', '\r']:
- line = line[:-1]
- # skip empty lines
- if line != '':
- self.ignorelist.append(line)
- f.close()
+ with codecs.open(filename, 'r', 'utf-8') as f:
+ for line in f.readlines():
+ # remove trailing newlines and carriage returns
+ while line[-1] in ['\n', '\r']:
+ line = line[:-1]
+ # skip empty lines
+ if line:
+ self.ignorelist.append(line)
except IOError:
pass
diff --git a/scripts/upload.py b/scripts/upload.py
index 9c27b78..db13900 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -129,8 +129,6 @@
suffix = 1 << 10
elif suffix == "mi":
suffix = 1 << 20
- else:
- pass # huh?
else:
suffix = 1
chunk_size = math.trunc(base * suffix)
diff --git a/scripts/welcome.py b/scripts/welcome.py
index eb1148f..d97f14b 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -748,10 +748,8 @@
if self.site.family.name != 'wikinews':
welcome_text = (welcome_text
% choice(self.defineSign()))
- if self.site.family.name == 'wiktionary' and \
- self.site.code == 'it':
- pass
- else:
+ if self.site.family.name != 'wiktionary' or \
+ self.site.code != 'it':
welcome_text += timeselected
elif (self.site.family.name != 'wikinews' and
self.site.code != 'it'):
diff --git a/tests/aspects.py b/tests/aspects.py
index 9a60cfc..d132ad2 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -546,7 +546,6 @@
% (cls.__name__, hostname))
pywikibot.exception(e2, tb=True)
e = e2
- pass
if e:
cls._checked_hostnames[hostname] = e
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index 228249e..3a98f9c 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Tests for the user interface."""
#
-# (C) Pywikibot team, 2008-2016
+# (C) Pywikibot team, 2008-2017
#
# Distributed under the terms of the MIT license.
#
@@ -670,7 +670,6 @@
@classmethod
def tearDownClass(cls):
cls.tearDownProcess()
- pass
def testOutputUnicodeText_no_transliterate(self):
self.sendstdin(
--
To view, visit https://gerrit.wikimedia.org/r/395696
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5d0c862a9cdb11ce4bd12d9d68b397b19c62d602
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits