Skip to content

Commit 8d136fc

Browse files
committed
Clean up pylint/pycodestyle warnings for py2 and py3
1 parent 91df70d commit 8d136fc

7 files changed

Lines changed: 41 additions & 41 deletions

File tree

bin/bugzilla

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ import socket
2323
import sys
2424
import tempfile
2525

26+
# pylint: disable=import-error
2627
if sys.version_info[0] >= 3:
27-
# pylint: disable=F0401,W0622,E0611
28+
# pylint: disable=no-name-in-module,redefined-builtin
2829
from xmlrpc.client import Fault, ProtocolError
2930
from urllib.parse import urlparse
3031
basestring = (str, bytes)
3132
else:
3233
from xmlrpclib import Fault, ProtocolError
3334
from urlparse import urlparse
35+
# pylint: enable=import-error
3436

3537
import requests.exceptions
3638

@@ -415,7 +417,7 @@ def _merge_field_opts(query, opt, parser):
415417
try:
416418
f, v = f.split('=', 1)
417419
query[f] = v
418-
except:
420+
except Exception:
419421
parser.error("Invalid field argument provided: %s" % (f))
420422

421423

@@ -685,8 +687,8 @@ def _format_output(bz, opt, buglist):
685687
elif fieldname == "comments":
686688
val = ""
687689
for c in getattr(b, "comments", []):
688-
val += ("\n* %s - %s:\n%s\n" %
689-
(c['time'], c.get("creator", c.get("author", "")), c['text']))
690+
val += ("\n* %s - %s:\n%s\n" % (c['time'],
691+
c.get("creator", c.get("author", "")), c['text']))
690692

691693
elif fieldname == "__unicode__":
692694
val = b.__unicode__()

bugzilla/base.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
from io import BytesIO
1919

20-
# pylint: disable=ungrouped-imports
20+
# pylint: disable=import-error
2121
if sys.version_info[0] >= 3:
22-
# pylint: disable=F0401,E0611
22+
# pylint: disable=no-name-in-module
2323
from configparser import SafeConfigParser
2424
from http.cookiejar import LoadError, MozillaCookieJar
2525
from urllib.parse import urlparse, parse_qsl
@@ -29,6 +29,7 @@
2929
from cookielib import LoadError, MozillaCookieJar
3030
from urlparse import urlparse, parse_qsl
3131
from xmlrpclib import Binary, Fault
32+
# pylint: enable=import-error
3233

3334

3435
from .apiversion import __version__
@@ -42,15 +43,11 @@
4243

4344

4445
def _detect_filetype(fname):
45-
# pylint: disable=E1103
46-
# E1103: Instance of 'bool' has no '%s' member
47-
# pylint confuses mimemagic to be of type 'bool'
4846
global mimemagic
4947

5048
if mimemagic is None:
5149
try:
52-
# pylint: disable=F0401
53-
# F0401: Unable to import 'magic' (import-error)
50+
# pylint: disable=import-error
5451
import magic
5552
mimemagic = magic.open(getattr(magic, "MAGIC_MIME_TYPE", 16))
5653
mimemagic.load()
@@ -513,7 +510,7 @@ def _set_bz_version(self, version):
513510
try:
514511
self.bz_ver_major, self.bz_ver_minor = [
515512
int(i) for i in version.split(".")[0:2]]
516-
except:
513+
except Exception:
517514
log.debug("version doesn't match expected format X.Y.Z, "
518515
"assuming 5.0", exc_info=True)
519516
self.bz_ver_major = 5
@@ -1349,10 +1346,6 @@ def build_update(self,
13491346
13501347
https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#create-bug
13511348
"""
1352-
# pylint: disable=W0221
1353-
# Argument number differs from overridden method
1354-
# Base defines it with *args, **kwargs, so we don't have to maintain
1355-
# the master argument list in 2 places
13561349
ret = {}
13571350

13581351
# These are only supported for rhbugzilla

bugzilla/transport.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
from logging import getLogger
88
import sys
99

10+
# pylint: disable=import-error
1011
if sys.version_info[0] >= 3:
11-
# pylint: disable=import-error,no-name-in-module
1212
from configparser import SafeConfigParser
13-
from urllib.parse import urlparse
13+
from urllib.parse import urlparse # pylint: disable=no-name-in-module
1414
from xmlrpc.client import Fault, ProtocolError, ServerProxy, Transport
1515
else:
1616
from ConfigParser import SafeConfigParser
17-
from urlparse import urlparse # pylint: disable=ungrouped-imports
17+
from urlparse import urlparse
1818
from xmlrpclib import Fault, ProtocolError, ServerProxy, Transport
19+
# pylint: enable=import-error
1920

2021
import requests
2122

@@ -94,7 +95,10 @@ def _ServerProxy__request(self, methodname, params):
9495
if 'Bugzilla_token' not in params[0]:
9596
params[0]['Bugzilla_token'] = self.token_cache.value
9697

97-
ret = super(_BugzillaServerProxy, self)._ServerProxy__request(methodname, params)
98+
# pylint: disable=no-member
99+
ret = super(_BugzillaServerProxy,
100+
self)._ServerProxy__request(methodname, params)
101+
# pylint: enable=no-member
98102

99103
if isinstance(ret, dict) and 'token' in ret.keys():
100104
self.token_cache.value = ret.get('token')
@@ -106,8 +110,6 @@ class _RequestsTransport(Transport):
106110

107111
def __init__(self, url, cookiejar=None,
108112
sslverify=True, sslcafile=None, debug=0):
109-
# pylint: disable=W0231
110-
# pylint does not handle multiple import of Transport well
111113
if hasattr(Transport, "__init__"):
112114
Transport.__init__(self, use_datetime=False)
113115

@@ -175,9 +177,10 @@ def _request_helper(self, url, request_body):
175177
except Fault:
176178
raise
177179
except Exception:
178-
# pylint: disable=W0201
179180
e = BugzillaError(str(sys.exc_info()[1]))
181+
# pylint: disable=attribute-defined-outside-init
180182
e.__traceback__ = sys.exc_info()[2]
183+
# pylint: enable=attribute-defined-outside-init
181184
raise e
182185

183186
def request(self, host, handler, request_body, verbose=0):

examples/apikey.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
" https://landfill.bugzilla.org/bugzilla-5.0-branch/userprefs.cgi")
2222
print("This is a test site, so no harm will come!\n")
2323

24+
# pylint: disable=undefined-variable
2425
if sys.version_info[0] >= 3:
2526
api_key = input("Enter Bugzilla API Key: ")
2627
else:
2728
api_key = raw_input("Enter Bugzilla API Key: ")
29+
# pylint: enable=undefined-variable
2830

2931
# API key usage assumes the API caller is storing the API key; if you would
3032
# like to use one of the login options that stores credentials on-disk for

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import shlex
99
import sys
1010

11+
# pylint: disable=import-error
1112
if sys.version_info[0] >= 3:
1213
from io import StringIO
1314
else:
1415
from StringIO import StringIO
16+
# pylint: enable=import-error
1517

1618
from bugzilla import Bugzilla, RHBugzilla
1719

tests/ro_functional.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Unit tests that do readonly functional tests against real bugzilla instances.
1212
'''
1313

14-
import sys
1514
import unittest
1615

1716
from bugzilla import Bugzilla, BugzillaError, RHBugzilla
@@ -80,13 +79,14 @@ def _testQuery(self, args, mincount, expectbug):
8079
return
8180

8281
self.assertTrue(len(out.splitlines()) >= mincount)
83-
self.assertTrue(bool([l for l in out.splitlines() if
84-
l.startswith("#" + expectbug)]))
82+
self.assertTrue(bool([l1 for l1 in out.splitlines() if
83+
l1.startswith("#" + expectbug)]))
8584

8685
# Check --ids output option
8786
out2 = self.clicomm(cli + " --ids")
8887
self.assertTrue(len(out.splitlines()) == len(out2.splitlines()))
89-
self.assertTrue(bool([l for l in out2.splitlines() if l == expectbug]))
88+
self.assertTrue(bool([l2 for l2 in out2.splitlines() if
89+
l2 == expectbug]))
9090

9191

9292
def _testQueryFull(self, bugid, mincount, expectstr):
@@ -173,8 +173,7 @@ def testURLQuery(self):
173173
bz = Bugzilla(url=self.url, use_creds=False)
174174
try:
175175
bz.query(bz.url_to_query(query_url))
176-
except BugzillaError:
177-
e = sys.exc_info()[1]
176+
except BugzillaError as e:
178177
self.assertTrue("derived from bugzilla" in str(e))
179178

180179

@@ -316,8 +315,7 @@ def testBugAutoRefresh(self):
316315
self.assertFalse(hasattr(bug, "component"))
317316
try:
318317
self.assertFalse(bool(bug.component))
319-
except:
320-
e = sys.exc_info()[1]
318+
except Exception as e:
321319
self.assertTrue("adjust your include_fields" in str(e))
322320

323321
def testExtraFields(self):

tests/rw_functional.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
import sys
1818
import unittest
1919

20+
# pylint: disable=import-error
2021
if sys.version_info[0] >= 3:
21-
# pylint: disable=F0401,E0611
22-
from urllib.parse import urlparse
22+
from urllib.parse import urlparse # pylint: disable=no-name-in-module
2323
else:
2424
from urlparse import urlparse
25+
# pylint: enable=import-error
2526

2627
import bugzilla
2728
from bugzilla import Bugzilla
@@ -122,8 +123,7 @@ def test03NewBugBasic(self):
122123
self.assertEqual(bug.summary, summary)
123124

124125
# Close the bug
125-
tests.clicomm("bugzilla modify --close NOTABUG %s" % bugid,
126-
bz)
126+
tests.clicomm("bugzilla modify --close NOTABUG %s" % bugid, bz)
127127
bug.refresh()
128128
self.assertEqual(bug.status, "CLOSED")
129129
self.assertEqual(bug.resolution, "NOTABUG")
@@ -810,9 +810,9 @@ def compare(data, newid):
810810
if have_admin:
811811
raise
812812
self.assertTrue(
813-
("Sorry, you aren't a member" in str(e)) or
814-
# bugzilla 5 error string
815-
("You are not allowed" in str(e)))
813+
("Sorry, you aren't a member" in str(e)) or
814+
# bugzilla 5 error string
815+
("You are not allowed" in str(e)))
816816

817817

818818
# Edit component
@@ -833,9 +833,9 @@ def compare(data, newid):
833833
if have_admin:
834834
raise
835835
self.assertTrue(
836-
("Sorry, you aren't a member" in str(e)) or
837-
# bugzilla 5 error string
838-
("You are not allowed" in str(e)))
836+
("Sorry, you aren't a member" in str(e)) or
837+
# bugzilla 5 error string
838+
("You are not allowed" in str(e)))
839839

840840
def test12SetCookie(self):
841841
bz = self.bzclass(self.url,

0 commit comments

Comments
 (0)