Skip to content

Commit 89a1fe4

Browse files
pcarruscagshbhmexe
authored andcommitted
Merge pull request #2633 from shbhmexe/fix/python-bare-except-clauses
fix: Replace bare except clauses with specific exception types in Python utilities Signed-off-by: shbhmexe <[email protected]>
2 parents 74e30cf + 296bce5 commit 89a1fe4

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

SU2_CFD/src/solvers/CRadP1Solver.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ void CRadP1Solver::BC_Isothermal_Wall(CGeometry *geometry, CSolver **solver_cont
282282
/*--- Get the specified wall emissivity from config ---*/
283283
Wall_Emissivity = config->GetWall_Emissivity(Marker_Tag);
284284

285+
/*--- Clamp emissivity to valid physical range [0,1] to prevent division by zero ---*/
286+
if (Wall_Emissivity < 0.0) {
287+
Wall_Emissivity = 0.0;
288+
}
289+
if (Wall_Emissivity > 1.0) {
290+
Wall_Emissivity = 1.0;
291+
}
292+
285293
/*--- Compute the constant for the wall theta ---*/
286294
Theta = Wall_Emissivity / (2.0*(2.0 - Wall_Emissivity));
287295

@@ -356,6 +364,14 @@ void CRadP1Solver::BC_Far_Field(CGeometry *geometry, CSolver **solver_container,
356364
/*--- Get the specified wall emissivity from config ---*/
357365
Wall_Emissivity = config->GetWall_Emissivity(Marker_Tag);
358366

367+
/*--- Clamp emissivity to valid physical range [0,1] to prevent division by zero ---*/
368+
if (Wall_Emissivity < 0.0) {
369+
Wall_Emissivity = 0.0;
370+
}
371+
if (Wall_Emissivity > 1.0) {
372+
Wall_Emissivity = 1.0;
373+
}
374+
359375
/*--- Compute the constant for the wall theta ---*/
360376
Theta = Wall_Emissivity / (2.0*(2.0 - Wall_Emissivity));
361377

@@ -430,6 +446,19 @@ void CRadP1Solver::BC_Marshak(CGeometry *geometry, CSolver **solver_container, C
430446
/*--- Get the specified wall emissivity from config ---*/
431447
Wall_Emissivity = config->GetWall_Emissivity(Marker_Tag);
432448

449+
/*--- Clamp emissivity to valid physical range [0,1] to prevent division by zero ---*/
450+
<<<<<<< HEAD
451+
if (Wall_Emissivity < 0.0) {
452+
Wall_Emissivity = 0.0;
453+
}
454+
if (Wall_Emissivity > 1.0) {
455+
Wall_Emissivity = 1.0;
456+
}
457+
=======
458+
if (Wall_Emissivity < 0.0) Wall_Emissivity = 0.0;
459+
if (Wall_Emissivity > 1.0) Wall_Emissivity = 1.0;
460+
>>>>>>> 46baac1286ba393e261fef83bced67d0d4d3f269
461+
433462
/*--- Compute the constant for the wall theta ---*/
434463
Theta = Wall_Emissivity / (2.0*(2.0 - Wall_Emissivity));
435464

SU2_CFD/src/solvers/CSolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,10 +3381,10 @@ void CSolver::Read_SU2_Restart_Metadata(CGeometry *geometry, CConfig *config, bo
33813381

33823382
/*--- External iteration ---*/
33833383

3384-
position = text_line.find ("ITER=",0);
3384+
position = text_line.find("ITER=", 0);
33853385
if (position != string::npos) {
3386-
// TODO: 'ITER=' has 5 chars, not 9!
3387-
text_line.erase (0,9); InnerIter_ = atoi(text_line.c_str());
3386+
text_line.erase(0, 5);
3387+
InnerIter_ = atoi(text_line.c_str()); // 'ITER=' has 5 chars
33883388
}
33893389

33903390
/*--- Angle of attack ---*/

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)