Skip to content

Commit dac92cc

Browse files
authored
Merge pull request #2633 from shbhmexe/fix/python-bare-except-clauses
fix: Replace bare except clauses with specific exception types in Python utilities
2 parents 74e30cf + 296bce5 commit dac92cc

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

SU2_PY/SU2/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ class DivergenceFailure(EvaluationFailure):
2828
readline.parse_and_bind("bind ^I rl_complete")
2929
else:
3030
readline.parse_and_bind("tab: complete")
31-
except:
32-
pass
31+
except Exception:
32+
pass # readline is optional, continue without it

SU2_PY/SU2/io/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(self, *args, **kwarg):
9494
self.read(filename)
9595
except IOError:
9696
print("Could not find config file: %s" % filename)
97-
except:
97+
except Exception:
9898
print("Unexpected error: ", sys.exc_info()[0])
9999
raise
100100
self._filename = filename

SU2_PY/SU2/util/bunch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __contains__(self, k):
8282
"""
8383
try:
8484
return hasattr(self, k) or dict.__contains__(self, k)
85-
except:
85+
except Exception:
8686
return False
8787

8888
# only called if k not found in normal places
@@ -140,7 +140,7 @@ def __setattr__(self, k, v):
140140
except AttributeError:
141141
try:
142142
self[k] = v
143-
except:
143+
except (KeyError, TypeError):
144144
raise AttributeError(k)
145145
else:
146146
object.__setattr__(self, k, v)

SU2_PY/SU2/util/ordered_bunch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __contains__(self, k):
9797
"""
9898
try:
9999
return hasattr(self, k) or dict.__contains__(self, k)
100-
except:
100+
except Exception:
101101
return False
102102

103103
# only called if k not found in normal places
@@ -160,7 +160,7 @@ def __setattr__(self, k, v):
160160
except AttributeError:
161161
try:
162162
self[k] = v
163-
except:
163+
except (KeyError, TypeError):
164164
raise AttributeError(k)
165165
else:
166166
object.__setattr__(self, k, v)

0 commit comments

Comments
 (0)