Skip to content

Commit d8495bf

Browse files
committed
fix: Improve Python code quality and PEP 8 compliance
- Replace improper `== None` and `!= None` comparisons with `is None` and `is not None` in multiple files. - Replace bare `except:` clauses with specific `except OSError:` in `topology_optimization.py`. Signed-off-by: shbhmexe <[email protected]>
1 parent d542249 commit d8495bf

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

Common/include/geometry/CGeometry.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*!
1+
/*!
22
* \file CGeometry.hpp
33
* \brief Headers of the main subroutines for creating the geometrical structure.
44
* The subroutines and functions are in the <i>CGeometry.cpp</i> file.
@@ -51,6 +51,7 @@ extern "C" {
5151
#include <climits>
5252
#include <memory>
5353
#include <unordered_map>
54+
#include <cstdint>
5455

5556
#include "primal_grid/CPrimalGrid.hpp"
5657
#include "dual_grid/CDualGrid.hpp"

Common/include/geometry/primal_grid/CPrimalGrid.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CPrimalGrid {
4949
unsigned long GlobalIndex_DomainElement;
5050

5151
std::unique_ptr<unsigned long[]> Nodes; /*!< \brief Global node indices of the element. */
52-
std::unique_ptr<long[]> Neighbor_Elements; /*!< \brief Vector to store the elements surrounding this element. */
52+
std::unique_ptr<long[]> Neighbor_Elements; /*!< \brief Vector to store the elements surronding this element. */
5353

5454
su2double Coord_CG[3] = {0.0}; /*!< \brief Coordinates of the center-of-gravity of the element. */
5555
su2double Volume; /*!< \brief Volume of the element. */

SU2_CFD/include/variables/CFlowVariable.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#pragma once
2828

29+
#include <algorithm>
30+
#include <cstdint>
31+
2932
#include "CVariable.hpp"
3033

3134
/*!

SU2_PY/SU2/io/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def load_data(file_name, var_names=None, file_format="infer", core_name="python_
115115
#: with filelock
116116

117117
# load specified varname into dictionary
118-
if var_names != None:
118+
if var_names is not None:
119119
# check for one item name array
120120
if isinstance(var_names, str):
121121
var_names = [
@@ -365,7 +365,7 @@ def rec2dict(array_in):
365365
# convert array
366366
elif isinstance(value, numpy.ndarray):
367367
# check for another struct level
368-
if value.dtype.names == None:
368+
if value.dtype.names is None:
369369
value = value.tolist()
370370
# telescoping
371371
else:

SU2_PY/SU2_CFD.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def main():
120120
options.wave_equation = options.wave_equation.upper() == "TRUE"
121121
options.heat_equation = options.heat_equation.upper() == "TRUE"
122122

123-
if options.filename == None:
123+
if options.filename is None:
124124
raise Exception("No config file provided. Use -f flag")
125125

126126
if options.with_MPI == True:
@@ -163,7 +163,7 @@ def main():
163163
# Finalize the solver and exit cleanly
164164
SU2Driver.Finalize()
165165

166-
if SU2Driver != None:
166+
if SU2Driver is not None:
167167
del SU2Driver
168168

169169

SU2_PY/parallel_computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def main():
6464
options.partitions = int(options.partitions)
6565
options.compute = options.compute.upper() == "TRUE"
6666

67-
if options.filename == None:
67+
if options.filename is None:
6868
raise Exception("No config file provided. Use -f flag")
6969

7070
parallel_computation(options.filename, options.partitions, options.compute)

SU2_PY/parallel_computation_fsi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def main():
6464
options.partitions = int(options.partitions)
6565
options.compute = options.compute.upper() == "TRUE"
6666

67-
if options.filename == None:
67+
if options.filename is None:
6868
raise Exception("No config file provided. Use -f flag")
6969

7070
parallel_computation(options.filename, options.partitions, options.compute)

SU2_PY/topology_optimization.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def obj_val(self, x):
123123
# clear previous output and run direct solver
124124
try:
125125
os.remove(self._objValFile)
126-
except:
126+
except OSError:
127127
pass
128128

129129
try:
@@ -136,7 +136,7 @@ def obj_val(self, x):
136136
break
137137
# the return code of mpirun is useless, we test the value of the function
138138
self._assert_isfinite(val)
139-
except:
139+
except OSError:
140140
raise RuntimeError("Objective function evaluation failed")
141141
# end
142142

@@ -150,7 +150,7 @@ def obj_der(self, x):
150150
# clear previous output and run direct solver
151151
try:
152152
os.remove(self._objDerFile)
153-
except:
153+
except OSError:
154154
pass
155155
N = x.shape[0]
156156
y = np.ndarray((N,))
@@ -167,7 +167,7 @@ def obj_der(self, x):
167167
self._assert_isfinite(val)
168168
y[i] = val * obj_scale / var_scale
169169
# end
170-
except:
170+
except OSError:
171171
raise RuntimeError("Objective gradient evaluation failed")
172172
# end
173173

@@ -186,7 +186,7 @@ def con_val(self, x):
186186
val = float(lines[1].split(",")[col])
187187
break
188188
self._assert_isfinite(val)
189-
except:
189+
except OSError:
190190
raise RuntimeError("Constraint function evaluation failed")
191191
# end
192192

@@ -200,7 +200,7 @@ def con_der(self, x):
200200
# clear previous output and run solver
201201
try:
202202
os.remove(self._conDerFile)
203-
except:
203+
except OSError:
204204
pass
205205
N = x.shape[0]
206206
y = np.ndarray((N,))
@@ -217,7 +217,7 @@ def con_der(self, x):
217217
self._assert_isfinite(val)
218218
y[i] = val * con_scale / var_scale
219219
# end
220-
except:
220+
except OSError:
221221
raise RuntimeError("Constraint function evaluation failed")
222222
# end
223223

@@ -295,7 +295,7 @@ def finished(self):
295295
return self._value == self._maxi
296296

297297
def value(self):
298-
if self._func == None:
298+
if self._func is None:
299299
return self._value
300300
else:
301301
return self._func(self._value)

0 commit comments

Comments
 (0)