Skip to content

Commit 0517588

Browse files
committed
Flake8 tweaks for issue #346
- The default flake8 was currently bumped (as we're not pinning a specific version in setup.py) and it brought with it a few new style checks. - Fix all instances of E722 (don't use bare except:) - Ignore E741 (single letter variable names) - Pin flake8 to this new version in setup.py so we don't hit another change
1 parent f104b1c commit 0517588

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
'pytest==3.0.5',
5858
'pytest-mock==1.5.0',
5959
'pytest-cov',
60-
'flake8',
60+
'flake8==3.5.0',
6161
'tox',
6262
'requests-mock==1.1.0',
6363
],

src/iris/api.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1850,15 +1850,15 @@ def on_post(self, req, resp):
18501850
s = socket.create_connection(sender_addr)
18511851

18521852
# Then try slaves
1853-
except:
1853+
except Exception:
18541854
if self.coordinator:
18551855
logger.exception('Failed contacting master (%s). Resorting to slaves.', sender_addr)
18561856
for slave_address in self.coordinator.get_current_slaves():
18571857
try:
18581858
logger.info('Trying slave %s..', slave_address)
18591859
s = socket.create_connection(slave_address)
18601860
break
1861-
except:
1861+
except Exception:
18621862
logger.exception('Failed reaching slave %s', slave_address)
18631863

18641864
# If none of that works, bail
@@ -3646,14 +3646,14 @@ def on_post(self, req, resp, username):
36463646
try:
36473647
cursor.execute('SELECT `id` FROM `mode` WHERE `name` = %s', params['src_mode'])
36483648
src_mode_id = cursor.fetchone()['id']
3649-
except:
3649+
except Exception:
36503650
msg = 'Invalid source mode.'
36513651
logger.exception(msg)
36523652
raise HTTPBadRequest(msg, msg)
36533653
try:
36543654
cursor.execute('SELECT `id` FROM `mode` WHERE `name` = %s', params['dst_mode'])
36553655
dst_mode_id = cursor.fetchone()['id']
3656-
except:
3656+
except Exception:
36573657
msg = 'Invalid destination mode.'
36583658
logger.exception(msg)
36593659
raise HTTPBadRequest(msg, msg)
@@ -3738,7 +3738,7 @@ def on_get(self, req, resp):
37383738
try:
37393739
with open(self.healthcheck_path) as f:
37403740
health = f.readline().strip()
3741-
except:
3741+
except Exception:
37423742
raise HTTPNotFound()
37433743
resp.status = HTTP_200
37443744
resp.content_type = 'text/plain'

src/iris/role_lookup/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_role_lookups(config):
1919
imported_modules.append(
2020
import_custom_module('iris.role_lookup', m)(config))
2121
logger.info('Loaded lookup modules: %s', m)
22-
except:
22+
except Exception:
2323
logger.exception('Failed to load role lookup module: %s', m)
2424

2525
return imported_modules

src/iris/sender/cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def init(api_host, config):
447447
re = iris_client.get('target_roles')
448448
if re.status_code == 200:
449449
break
450-
except:
450+
except Exception:
451451
pass
452452
api_chk_cnt += 1
453453
logger.warning(

src/iris/sphinx_extension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_routes(app):
3232
if handler.__getattribute__('func_name') == 'method_not_allowed':
3333
# method not defined for route
3434
continue
35-
except:
35+
except Exception:
3636
pass
3737
yield method, curr_node.uri_template, handler
3838

src/iris/vendors/iris_smtp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def send_email(self, message, customizations=None):
145145

146146
try:
147147
conn.quit()
148-
except:
148+
except Exception:
149149
pass
150150

151151
# If we can't send it, try reconnecting and then sending it one more time before
@@ -180,7 +180,7 @@ def cleanup(self):
180180
logger.info('Trying to quit smtp connection to %s', self.last_conn_server)
181181
try:
182182
self.last_conn.quit()
183-
except:
183+
except Exception:
184184
pass
185185

186186
@classmethod

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ envlist = py27
44
[flake8]
55
exclude = .tox,./build
66
filename = *.py
7-
ignore = E501,E101
7+
ignore = E501,E101,E741
88

99
[testenv]
1010
deps =

0 commit comments

Comments
 (0)