mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Fix E722 ('do not use bare except') (#3239)
The new version of flake8 includes a check for not using bare except. We should avoid this since it catches things like KeyboardInterrupt.
This commit is contained in:
@ -116,7 +116,7 @@ def is_iterable(obj):
|
||||
try:
|
||||
iter(obj)
|
||||
return True
|
||||
except:
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
@ -210,7 +210,7 @@ class TestCase(unittest.TestCase):
|
||||
try:
|
||||
self.assertLessEqual(abs(x - y), prec, message)
|
||||
return
|
||||
except:
|
||||
except (TypeError, AssertionError):
|
||||
pass
|
||||
super(TestCase, self).assertEqual(x, y, message)
|
||||
|
||||
@ -242,7 +242,7 @@ class TestCase(unittest.TestCase):
|
||||
try:
|
||||
self.assertGreaterEqual(abs(x - y), prec, message)
|
||||
return
|
||||
except:
|
||||
except (TypeError, AssertionError):
|
||||
pass
|
||||
super(TestCase, self).assertNotEqual(x, y, message)
|
||||
|
||||
|
@ -35,7 +35,7 @@ import os as _dl_flags
|
||||
# or there is risk that later c modules will segfault when importing numpy
|
||||
try:
|
||||
import numpy as np
|
||||
except:
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# first check if the os package has the required flags
|
||||
|
@ -404,7 +404,7 @@ class Module(object):
|
||||
param = param.data
|
||||
try:
|
||||
own_state[name].copy_(param)
|
||||
except:
|
||||
except Exception:
|
||||
raise RuntimeError('While copying the parameter named {}, ' +
|
||||
'whose dimensions in the model are {} and ' +
|
||||
'whose dimensions in the checkpoint are {}.'
|
||||
|
@ -150,7 +150,7 @@ def _save(obj, f, pickle_module, pickle_protocol):
|
||||
try:
|
||||
source_file = inspect.getsourcefile(obj)
|
||||
source = inspect.getsource(obj)
|
||||
except: # saving the source is optional, so we can ignore any errors
|
||||
except Exception: # saving the source is optional, so we can ignore any errors
|
||||
warnings.warn("Couldn't retrieve source code for container of "
|
||||
"type " + obj.__name__ + ". It won't be checked "
|
||||
"for correctness upon loading.")
|
||||
|
@ -49,7 +49,7 @@ def _pin_memory_loop(in_queue, out_queue, done_event):
|
||||
while True:
|
||||
try:
|
||||
r = in_queue.get()
|
||||
except:
|
||||
except Exception:
|
||||
if done_event.is_set():
|
||||
return
|
||||
raise
|
||||
|
Reference in New Issue
Block a user