jenkins-bot has submitted this change and it was merged.
Change subject: Use flake8-putty 0.3.2 auto ignore
......................................................................
Use flake8-putty 0.3.2 auto ignore
Instead of flake8's general # noqa, flake8-putty 0.3.2 allows
individual codes to be disabled with '# flake8: disable=xxx'
The noqa in generate_*.py regarding PYWIKIBOT2_NO_USER_CONFIG
were to prevent E402 (module level import not at top of file)
however this is already unconditionally ignored by flake8 and pep8.
The noqa in editor.py was added in 728524b, when it was an
unused variable. It is now used, so no error is generated.
Change-Id: I21ee56755311c4c5f9cd427e2ce8aca35568b7f7
---
M generate_family_file.py
M generate_user_files.py
M pwb.py
M pywikibot/bot.py
M pywikibot/comms/http.py
M pywikibot/editor.py
M pywikibot/exceptions.py
M pywikibot/page.py
M pywikibot/site.py
M pywikibot/tools/__init__.py
M pywikibot/tools/ip.py
M pywikibot/userinterfaces/gui.py
M pywikibot/userinterfaces/terminal_interface_base.py
M scripts/flickrripper.py
M scripts/interwiki.py
M scripts/maintenance/cache.py
M scripts/script_wui.py
M setup.py
M tests/__init__.py
M tests/data_ingestion_tests.py
M tests/pagegenerators_tests.py
M tests/site_tests.py
M tests/utils.py
M tox.ini
24 files changed, 63 insertions(+), 48 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_family_file.py b/generate_family_file.py
index fd960a7..ddfe809 100755
--- a/generate_family_file.py
+++ b/generate_family_file.py
@@ -30,8 +30,8 @@
# Disable user-config checks so the family can be created first,
# and then used when generating the user-config
-_orig_no_user_config = os.environ.get('PYWIKIBOT2_NO_USER_CONFIG') # noqa
-os.environ['PYWIKIBOT2_NO_USER_CONFIG'] = '2' # noqa
+_orig_no_user_config = os.environ.get('PYWIKIBOT2_NO_USER_CONFIG')
+os.environ['PYWIKIBOT2_NO_USER_CONFIG'] = '2'
from pywikibot.site_detect import MWSite as Wiki
diff --git a/generate_user_files.py b/generate_user_files.py
index 7085816..8e59c8b 100755
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -18,8 +18,8 @@
from warnings import warn
# Disable user-config usage as we are creating it here
-_orig_no_user_config = os.environ.get('PYWIKIBOT2_NO_USER_CONFIG') # noqa
-os.environ['PYWIKIBOT2_NO_USER_CONFIG'] = '2' # noqa
+_orig_no_user_config = os.environ.get('PYWIKIBOT2_NO_USER_CONFIG')
+os.environ['PYWIKIBOT2_NO_USER_CONFIG'] = '2'
import pywikibot
diff --git a/pwb.py b/pwb.py
index 395019e..7290738 100755
--- a/pwb.py
+++ b/pwb.py
@@ -72,13 +72,13 @@
"""
global pwb
try:
- import pywikibot # noqa
+ import pywikibot # flake8: disable=F811
pwb = pywikibot
except RuntimeError:
remove_modules()
os.environ['PYWIKIBOT2_NO_USER_CONFIG'] = '2'
- import pywikibot # noqa
+ import pywikibot # flake8: disable=E402
pwb = pywikibot
@@ -184,7 +184,7 @@
if sys.platform == 'win32' and sys.version_info[0] < 3:
_pwb_dir = str(_pwb_dir)
os.environ[str('PYWIKIBOT2_DIR_PWB')] = _pwb_dir
- import pywikibot # noqa
+ import pywikibot # flake8: disable=F401
except RuntimeError as err:
# user-config.py to be created
print("NOTE: 'user-config.py' was not found!")
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index ed2c451..2788b86 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -84,18 +84,20 @@
from pywikibot import config
from pywikibot import daemonize
from pywikibot import version
-from pywikibot.bot_choice import ( # noqa: unused imports
+from pywikibot.bot_choice import ( # flake8: disable=F401 (unused imports)
Option, StandardOption, NestedOption, IntegerOption, ContextOption,
ListOption, OutputProxyOption, HighlightContextOption,
ChoiceException, QuitKeyboardInterrupt,
)
-from pywikibot.logging import CRITICAL, ERROR, INFO, WARNING # noqa: unused
+from pywikibot.logging import ( # flake8: disable=F401
+ CRITICAL, ERROR, INFO, WARNING,
+)
from pywikibot.logging import DEBUG, INPUT, STDOUT, VERBOSE
from pywikibot.logging import (
add_init_routine,
debug, error, exception, log, output, stdout, warning,
)
-from pywikibot.logging import critical # noqa: unused
+from pywikibot.logging import critical # flake8: disable=F401
from pywikibot.tools import deprecated, deprecated_args, PY2, PYTHON_VERSION
from pywikibot.tools._logging import (
LoggingFormatter as _LoggingFormatter,
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 260f486..5ae05de 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -93,7 +93,7 @@
message = 'Closing network session.'
if hasattr(sys, 'last_type'):
# we quit because of an exception
- print(sys.last_type) # noqa: print
+ print(sys.last_type) # flake8: disable=T003 (print)
critical(message)
else:
log(message)
diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index bef3119..e878a5d 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -23,7 +23,7 @@
from pywikibot.tools import deprecated
try:
- from pywikibot.userinterfaces import gui # noqa
+ from pywikibot.userinterfaces import gui
except ImportError as e:
gui = e
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 8c50c21..a59b69b 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -160,7 +160,7 @@
if '%(' in self.message and ')s' in self.message:
super(PageRelatedError, self).__init__(
- self.message % self.__dict__) # noqa: H501
+ self.message % self.__dict__)
else:
super(PageRelatedError, self).__init__(self.message % page)
diff --git a/pywikibot/page.py b/pywikibot/page.py
index dc83ae4..9c1ef9d 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -40,7 +40,7 @@
from html import entities as htmlentitydefs
from urllib.parse import quote_from_bytes, unquote_to_bytes
else:
- chr = unichr # noqa
+ chr = unichr # flake8 F821 (undefined name) disabled by tox.ini
import htmlentitydefs
from urllib import quote as quote_from_bytes, unquote as unquote_to_bytes
@@ -67,7 +67,7 @@
first_upper, remove_last_args, _NotImplementedWarning,
OrderedDict, Counter,
)
-from pywikibot.tools.ip import ip_regexp # noqa & deprecated
+from pywikibot.tools.ip import ip_regexp # flake8: disable=F401 (unused import)
from pywikibot.tools.ip import is_IP
diff --git a/pywikibot/site.py b/pywikibot/site.py
index c421fbf..1eade5b 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -5739,7 +5739,7 @@
3)
if isinstance(ignore_warnings, Iterable):
ignored_warnings = ignore_warnings
- ignore_warnings = lambda warnings: all( # noqa: E731
+ ignore_warnings = lambda warnings: all( # flake8: disable=E731
w.code in ignored_warnings for w in warnings)
ignore_all_warnings = not callable(ignore_warnings) and ignore_warnings
if text is None:
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 714f047..478a1dd 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -146,9 +146,9 @@
else:
- from collections import Counter # noqa ; unused
+ from collections import Counter # flake8: disable=F401 (unused import)
from collections import OrderedDict
- from itertools import count # noqa ; unused
+ from itertools import count # flake8: disable=F401 (unused import)
def empty_iterator():
diff --git a/pywikibot/tools/ip.py b/pywikibot/tools/ip.py
index dca6ef8..aca5045 100644
--- a/pywikibot/tools/ip.py
+++ b/pywikibot/tools/ip.py
@@ -15,7 +15,7 @@
from distutils.version import StrictVersion
from warnings import warn
-from pywikibot.tools import DeprecatedRegex
+from pywikibot.tools import DeprecatedRegex, UnicodeType
_ipaddress_e = _ipaddr_e = _ipaddr_version = None
@@ -61,7 +61,7 @@
def ip_address_patched(IP):
"""Safe ip_address."""
- return orig_ip_address(unicode(IP)) # noqa
+ return orig_ip_address(UnicodeType(IP))
ip_address = ip_address_patched
except ValueError:
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py
index cce5a42..4d3e33e 100644
--- a/pywikibot/userinterfaces/gui.py
+++ b/pywikibot/userinterfaces/gui.py
@@ -36,6 +36,7 @@
import pywikibot
from pywikibot import __url__
+from pywikibot.tools import PY2, UnicodeType
class TextEditor(ScrolledText):
@@ -415,8 +416,8 @@
# if the editbox contains ASCII characters only, get() will
# return string, otherwise unicode (very annoying). We only want
# it to return unicode, so we work around this.
- if sys.version[0] == 2 and isinstance(self.text, str):
- self.text = unicode(self.text) # noqa
+ if PY2 and isinstance(self.text, str):
+ self.text = UnicodeType(self.text)
self.parent.destroy()
def debug(self, event=None):
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py
b/pywikibot/userinterfaces/terminal_interface_base.py
index f151ee4..6aa3d2b 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -228,7 +228,7 @@
if not PY2:
return input()
else:
- return raw_input() # noqa
+ return raw_input()
def input(self, question, password=False, default='', force=False):
"""
diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py
index 7fa9bce..7d549aa 100755
--- a/scripts/flickrripper.py
+++ b/scripts/flickrripper.py
@@ -51,7 +51,7 @@
except ImportError as e:
print('This script requires the python flickrapi module. \n'
'See:
http://stuvel.eu/projects/flickrapi') # noqa: print
- print(e) # noqa: print
+ print(e) # flake8: disable=T003 (print)
sys.exit(1)
import pywikibot
@@ -355,7 +355,7 @@
user_id=user_id, tags=tags,
per_page='100', page='1')
pages = photos.find('photos').attrib['pages']
- gen = lambda i: flickr.groups_pools_getPhotos( # noqa: E731
+ gen = lambda i: flickr.groups_pools_getPhotos( # flake8: disable=E731
group_id=group_id, user_id=user_id, tags=tags,
per_page='100', page=i
).find('photos').getchildren()
@@ -365,7 +365,7 @@
photos = flickr.photosets_getPhotos(photoset_id=photoset_id,
per_page='100', page='1')
pages = photos.find('photoset').attrib['pages']
- gen = lambda i: flickr.photosets_getPhotos( # noqa: E731
+ gen = lambda i: flickr.photosets_getPhotos( # flake8: disable=E731
photoset_id=photoset_id, per_page='100', page=i
).find('photoset').getchildren()
#
https://www.flickr.com/services/api/flickr.people.getPublicPhotos.html
@@ -374,7 +374,7 @@
photos = flickr.people_getPublicPhotos(user_id=user_id,
per_page='100', page='1')
pages = photos.find('photos').attrib['pages']
- gen = lambda i: flickr.people_getPublicPhotos( # noqa: E731
+ gen = lambda i: flickr.people_getPublicPhotos( # flake8: disable=E731
user_id=user_id, per_page='100', page=i
).find('photos').getchildren()
for i in range(1, int(pages) + 1):
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 4a5016a..dafe079 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -2332,10 +2332,10 @@
if not globalvar.summary and \
len(adding) + len(removing) + len(modifying) <= 3:
# Use an extended format for the string linking to all added pages.
- fmt = lambda d, site: unicode(d[site]) # noqa: E731
+ fmt = lambda d, site: unicode(d[site]) # flake8: disable=E731
else:
# Use short format, just the language code
- fmt = lambda d, site: site.code # noqa: E731
+ fmt = lambda d, site: site.code # flake8: disable=E731
mods = mcomment = u''
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index 5eeeef8..7fe3d12 100755
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -76,8 +76,9 @@
from pywikibot.data import api
-from pywikibot.page import User # noqa
-from pywikibot.site import APISite, DataSite, LoginStatus # noqa
+# The follow attributes are used by eval()
+from pywikibot.page import User # flake8: disable=F401 (unused import)
+from pywikibot.site import APISite, DataSite, LoginStatus # flake8: disable=F401
class ParseError(Exception):
diff --git a/scripts/script_wui.py b/scripts/script_wui.py
index 81441bc..e8bc5bb 100755
--- a/scripts/script_wui.py
+++ b/scripts/script_wui.py
@@ -97,7 +97,7 @@
if sys.version_info[0] > 2:
import _thread as thread
else:
- import thread # noqa: H237: module does not exist in Python 3
+ import thread # flake8: disable=H237 (module does not exist in Python 3)
bot_config = {
diff --git a/setup.py b/setup.py
index 97f121a..2457f81 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@
try:
# Work around a traceback on Python < 2.7.4 and < 3.3.1
#
http://bugs.python.org/issue15881#msg170215
- import multiprocessing # noqa: unused
+ import multiprocessing # flake8: disable=F401 (unused import)
except ImportError:
pass
@@ -108,7 +108,7 @@
if PYTHON_VERSION < (2, 7, 3):
# work around distutils hardcoded unittest dependency
# work around T106512
- import unittest # noqa
+ import unittest # flake8: disable=F401 (unused import)
if 'test' in sys.argv:
import unittest2
sys.modules['unittest'] = unittest2
@@ -142,7 +142,7 @@
script_deps['data_ingestion.py'] = extra_deps['csv']
try:
- import bz2 # noqa: unused import
+ import bz2 # flake8: disable=F401 (unused import)
except ImportError:
# Use bz2file if the python is not compiled with bz2 support.
dependencies.append('bz2file')
diff --git a/tests/__init__.py b/tests/__init__.py
index c7a66bf..e61f37c 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -13,7 +13,7 @@
import os
import warnings
-__all__ = ('requests', 'TestRequest',
+__all__ = ('requests', 'unittest', 'TestRequest',
'patch_request', 'unpatch_request')
# Verify that the unit tests have a base working environment:
@@ -22,7 +22,7 @@
# however if unavailable this will fail on use; see pywikibot/tools.py
# - unittest2; see below
# - mwparserfromhell is optional, so is only imported in textlib_tests
-import requests # noqa
+import requests
from pywikibot.tools import PYTHON_VERSION
diff --git a/tests/data_ingestion_tests.py b/tests/data_ingestion_tests.py
index d9ec3f3..3a8fae2 100644
--- a/tests/data_ingestion_tests.py
+++ b/tests/data_ingestion_tests.py
@@ -61,14 +61,14 @@
def test_getDescription(self):
"""Test getDescription()."""
self.assertEqual(self.obj.getDescription('CrystalTemplate'),
-"""{{CrystalTemplate
+ str("""{{CrystalTemplate
|author=KDE artists {{!}} Silstor
|description.en="Sounds" icon
|license=LGPL
|name=Sound icon
|set=Crystal SVG icon set
|source=http://commons.wikimedia.org/wiki/File:Sound-icon.svg
-}}""") # noqa
+}}"""))
class TestCSVReader(TestCase):
@@ -99,7 +99,7 @@
def test_getDescription(self):
"""Test getDescription()."""
self.assertEqual(self.obj.getDescription('CrystalTemplate'),
-"""{{CrystalTemplate
+ str("""{{CrystalTemplate
|author=KDE artists {{!}} Silstor
|description.en="Sounds" icon
|license=LGPL
@@ -107,7 +107,7 @@
|set=Crystal SVG icon set
|source=http://commons.wikimedia.org/wiki/File:Sound-icon.svg
|url=http://upload.wikimedia.org/wikipedia/commons/f/fc/MP_sounds.png
-}}""") # noqa
+}}"""))
class TestDataIngestionBot(ScriptMainTestCase):
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index f4f69f8..b5b8f57 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -12,6 +12,7 @@
import calendar
import datetime
import json
+import logging
import sys
from distutils.version import LooseVersion
@@ -1088,7 +1089,7 @@
"""Setup test class."""
super(LiveRCPageGeneratorTestCase, cls).setUpClass()
try:
- import socketIO_client # noqa
+ import socketIO_client
except ImportError:
raise unittest.SkipTest('socketIO_client not available')
@@ -1099,7 +1100,6 @@
def test_RC_pagegenerator_result(self):
"""Test RC pagegenerator."""
- import logging
lgr = logging.getLogger('socketIO_client')
lgr.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 9922170..8846e6d 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1151,6 +1151,10 @@
def test_logpages(self):
"""Test the deprecated site.logpages() method."""
+ # pyflakes fix for Python 3
+ if not PY2:
+ long = int
+
le = list(self.site.logpages(number=10))
self.assertOneDeprecation()
self.assertLessEqual(len(le), 10)
@@ -1159,7 +1163,7 @@
self.assertIsInstance(entry[0], pywikibot.Page)
self.assertIsInstance(entry[1], basestring)
self.assertIsInstance(
- entry[2], long if PY2 and entry[2] > sys.maxint else int) # noqa
+ entry[2], long if PY2 and entry[2] > sys.maxint else int)
self.assertIsInstance(entry[3], basestring)
def test_logpages_dump(self):
diff --git a/tests/utils.py b/tests/utils.py
index 9c09991..73da80d 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -43,7 +43,7 @@
)
from tests import _pwb_py
-from tests import unittest # noqa
+from tests import unittest
from tests import unittest_print
OSWIN32 = (sys.platform == 'win32')
diff --git a/tox.ini b/tox.ini
index d9fb25d..1fad75b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -31,7 +31,7 @@
pyflakes >= 1.1
hacking
flake8-docstrings<0.2.2
- flake8-putty>=0.2.0
+ flake8-putty>=0.3.2
flake8-coding
flake8-future-import
flake8-string-format
@@ -47,7 +47,7 @@
deps = flake8
pyflakes >= 1.1
flake8-docstrings<0.2.2
- flake8-putty>=0.2.0
+ flake8-putty>=0.3.2
[testenv:nose]
commands =
@@ -116,8 +116,8 @@
max_line_length = 100
accept-encodings = utf-8
require-code = true
+putty-auto-ignore = true
putty-ignore =
- pwb.py,scripts/interwiki.py,scripts/flickrripper.py,pywikibot/site.py, /# noqa: E731/
: +E731
generate_family_file.py : +T001, T003
pwb.py : +T001, T003
pywikibot/date.py,pywikibot/family.py,pywikibot/fixes.py,pywikibot/textlib.py,pywikibot/userinterfaces/terminal_interface_unix.py,pywikibot/userinterfaces/terminal_interface_win32.py,pywikibot/families/wikipedia_family.py
: +E241
@@ -134,7 +134,14 @@
scripts/makecat.py : +D103
scripts/interwiki.py,/""/ : +P102
pywikibot/__init__.py,/link_regex/ : +P103
+ # undefined names on Python 3:
+ pywikibot/page.py , /chr = unichr/ , python_version >= '3' : +F821
+ pywikibot/userinterfaces/terminal_interface_base.py , /raw_input\(\)/ ,
python_version >= '3' : +F821
+ # invalidly detected as {} format string:
tests/textlib_tests.py,/self.assert.*{{/ : +P103
+ # __dict__ used in a discouraged manner
+ # regex matches the first physical line of logical line of the error
+ pywikibot/exceptions.py , /PageRelatedError.*__init__/ : +H501
[pep8]
# see explanations above
--
To view, visit
https://gerrit.wikimedia.org/r/282082
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I21ee56755311c4c5f9cd427e2ce8aca35568b7f7
Gerrit-PatchSet: 6
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: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>