Skip to content

Commit

Permalink
Fix new flake8 tests (#2274)
Browse files Browse the repository at this point in the history
* Ignore new flake8 tests

These new exclusions include:
* E722 - bare except
* E741 - ambiguous variable name
* E742 - ambiguous class definition

* Update flake8 calls for corrected exclusions

* Revert flake8 test exclusions

* Fix instance of E742 violation

* Fix instance of E741 violation

* Replace bare except with BaseException

* Replace bare except with AttributeError

* Remove unnecessary try/except
  • Loading branch information
dlstadther authored Nov 4, 2017
1 parent 103136d commit 56fbbcb
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion luigi/contrib/docker_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def run(self):
container_name = self.name
try:
message = e.message
except:
except AttributeError:
message = str(e)
self.__logger.error("Container " + container_name +
" exited with non zero code: " + message)
Expand Down
2 changes: 1 addition & 1 deletion luigi/contrib/hadoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ def writer(self, outputs, stdout, stderr=sys.stderr):
# JSON is already serialized, so we put `self.serialize` in a else statement.
output = map(self.serialize, output)
print("\t".join(output), file=stdout)
except:
except BaseException:
print(output, file=stderr)
raise

Expand Down
10 changes: 4 additions & 6 deletions luigi/contrib/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,10 @@ def run(self):
credentials=self._credentials())

logger.info('Executing unload query from task: {name}'.format(name=self.__class__))
try:
cursor = connection.cursor()
cursor.execute(unload_query)
logger.info(cursor.statusmessage)
except:
raise

cursor = connection.cursor()
cursor.execute(unload_query)
logger.info(cursor.statusmessage)

# Update marker table
self.output().touch(connection)
Expand Down
2 changes: 1 addition & 1 deletion luigi/contrib/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def __copy_multipart(self, pool, src_bucket, src_key, dst_bucket, dst_key, part_
mp.complete_upload()
return mp.key_name

except:
except BaseException:
logger.info('Error during multipart s3 copy for %s/%s to %s/%s...', src_bucket, src_key, dst_bucket, dst_key)
# cancel the copy so we don't get charged for storage consumed by copied parts
if mp:
Expand Down
2 changes: 1 addition & 1 deletion luigi/db_task_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _session(self, session=None):
session = self.session_factory()
try:
yield session
except:
except BaseException:
session.rollback()
raise
else:
Expand Down
2 changes: 1 addition & 1 deletion luigi/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def run(self):
response = None
try:
response = self._scheduler.ping(worker=self._worker_id)
except: # httplib.BadStatusLine:
except BaseException: # httplib.BadStatusLine:
logger.warning('Failed pinging scheduler')

# handle rpc messages
Expand Down
12 changes: 6 additions & 6 deletions test/contrib/hdfs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_with_close(self):
try:
if self.fs.exists(testpath):
self.fs.remove(testpath, skip_trash=True)
except:
except BaseException:
if self.fs.exists(self._test_dir()):
self.fs.remove(self._test_dir(), skip_trash=True)

Expand All @@ -159,7 +159,7 @@ def test_with_noclose(self):
try:
if self.fs.exists(testpath):
self.fs.remove(testpath, skip_trash=True)
except:
except BaseException:
if self.fs.exists(self._test_dir()):
self.fs.remove(self._test_dir(), skip_trash=True)

Expand All @@ -175,7 +175,7 @@ def test_target_path_exists(self):
try:
if self.fs.exists(testpath):
self.fs.remove(testpath, skip_trash=True)
except:
except BaseException:
if self.fs.exists(self._test_dir()):
self.fs.remove(self._test_dir(), skip_trash=True)

Expand All @@ -195,7 +195,7 @@ def test_target_path_exists_rename_fails_hadoopcli(self, remove):
try:
if self.fs.exists(testpath):
self.fs.remove(testpath, skip_trash=True)
except:
except BaseException:
if self.fs.exists(self._test_dir()):
self.fs.remove(self._test_dir(), skip_trash=True)

Expand All @@ -214,7 +214,7 @@ def test_target_path_exists_rename_fails_snakebite(self, remove, rename):
try:
if self.fs.exists(testpath):
self.fs.remove(testpath, skip_trash=True)
except:
except BaseException:
if self.fs.exists(self._test_dir()):
self.fs.remove(self._test_dir(), skip_trash=True)

Expand Down Expand Up @@ -390,7 +390,7 @@ def test_slow_exists(self):
target = hdfs.HdfsTarget(self._test_file())
try:
target.remove(skip_trash=True)
except:
except BaseException:
pass

self.assertFalse(self.fs.exists(target.path))
Expand Down
4 changes: 2 additions & 2 deletions test/decorator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def requires(self):


@inherits(G)
class I(luigi.Task):
class I_task(luigi.Task):

def requires(self):
return F(**common_params(self, F))
Expand Down Expand Up @@ -183,7 +183,7 @@ def setUp(self):
self.g_changed = G(param1="changing the default")
self.h = H()
self.h_null = H_null()
self.i = I()
self.i = I_task()
self.k_shouldfail = K_shouldfail()
self.k_shouldsucceed = K_shouldsucceed()
self.k_wrongparamsorder = K_wrongparamsorder()
Expand Down
4 changes: 2 additions & 2 deletions test/parameter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,11 @@ def complete(self):
def testListWithNamespaceCli(self):
class A(luigi.Task):
task_namespace = 'mynamespace'
l = luigi.ListParameter(default=[1, 2, 3])
l_param = luigi.ListParameter(default=[1, 2, 3])
expected = luigi.ListParameter()

def complete(self):
if self.l != self.expected:
if self.l_param != self.expected:
raise ValueError
return True

Expand Down
2 changes: 1 addition & 1 deletion test/simulate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def is_writable():
pass
open(fn, 'w').close()
os.remove(fn)
except:
except BaseException:
exists = False

return unittest.skipIf(not exists, 'Can\'t write to temporary directory')
Expand Down

0 comments on commit 56fbbcb

Please sign in to comment.