Skip to content

Commit 3261fef

Browse files
authored
fix(SU2_PY, SU2_CFD): Python 3 compatibility and C++ code quality improvements (#2643)
Python fixes: - Replace deprecated .iteritems() with .items() in bunch.py, ordered_bunch.py - Replace deprecated .itervalues() with .values() in ordered_dict.py - Replace keys().sort() with sorted(keys()) in bunch.py as dict.keys() returns a view object in Python 3 - Replace unicode type with str in data.py (unicode was merged into str in Python 3) - Replace 'raise StopIteration' with 'return' in switch.py (PEP 479: raising StopIteration inside a generator is deprecated in Python 3.7+ and causes RuntimeError) C++ fixes: - Remove redundant '== true' boolean comparison in CSpeciesFlameletSolver.cpp (line 443) These changes ensure the SU2 Python utilities work correctly with Python 3.x and improve C++ code quality. Signed-off-by: shbhmexe <[email protected]>
1 parent 2c0049f commit 3261fef

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

SU2_CFD/src/solvers/CSpeciesFlameletSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void CSpeciesFlameletSolver::BC_Isothermal_Wall_Generic(CGeometry* geometry, CSo
440440
/*--- Check if the node belongs to the domain (i.e., not a halo node). ---*/
441441

442442
if (geometry->nodes->GetDomain(iPoint)) {
443-
if (config->GetMarker_StrongBC(Marker_Tag) == true) {
443+
if (config->GetMarker_StrongBC(Marker_Tag)) {
444444
/*--- Initial guess for enthalpy value. ---*/
445445
enth_wall = nodes->GetSolution(iPoint, I_ENTH);
446446

SU2_PY/SU2/io/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def rec2dict(array_in):
359359
value = array_in[key].tolist()[0][0]
360360

361361
# convert string
362-
if isinstance(value[0], unicode):
362+
if isinstance(value[0], str):
363363
value = str(value[0])
364364

365365
# convert array

SU2_PY/SU2/util/bunch.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,13 @@ def __repr__(self):
194194
195195
(*) Invertible so long as collection contents are each repr-invertible.
196196
"""
197-
keys = self.keys()
198-
keys.sort()
197+
keys = sorted(self.keys())
199198
args = ", ".join(["%s=%r" % (key, self[key]) for key in keys])
200199
return "%s(%s)" % (self.__class__.__name__, args)
201200

202201
def __str__(self):
203202
"""String-form of a OrderedBunch."""
204-
keys = self.keys()
205-
keys.sort()
203+
keys = sorted(self.keys())
206204
args = ", ".join(["%s=%r" % (key, self[key]) for key in keys])
207205
return "{%s}" % args
208206

@@ -247,7 +245,7 @@ def bunchify(x):
247245
nb. As dicts are not hashable, they cannot be nested in sets/frozensets.
248246
"""
249247
if isinstance(x, dict):
250-
return Bunch((k, bunchify(v)) for k, v in x.iteritems())
248+
return Bunch((k, bunchify(v)) for k, v in x.items())
251249
elif isinstance(x, (list, tuple)):
252250
return type(x)(bunchify(v) for v in x)
253251
else:
@@ -273,7 +271,7 @@ def unbunchify(x):
273271
nb. As dicts are not hashable, they cannot be nested in sets/frozensets.
274272
"""
275273
if isinstance(x, dict):
276-
return dict((k, unbunchify(v)) for k, v in x.iteritems())
274+
return dict((k, unbunchify(v)) for k, v in x.items())
277275
elif isinstance(x, (list, tuple)):
278276
return type(x)(unbunchify(v) for v in x)
279277
else:

SU2_PY/SU2/util/ordered_bunch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def ordered_bunchify(x):
265265
nb. As dicts are not hashable, they cannot be nested in sets/frozensets.
266266
"""
267267
if isinstance(x, dict):
268-
return OrderedBunch((k, ordered_bunchify(v)) for k, v in x.iteritems())
268+
return OrderedBunch((k, ordered_bunchify(v)) for k, v in x.items())
269269
elif isinstance(x, (list, tuple)):
270270
return type(x)(ordered_bunchify(v) for v in x)
271271
else:
@@ -291,9 +291,9 @@ def ordered_unbunchify(x):
291291
nb. As dicts are not hashable, they cannot be nested in sets/frozensets.
292292
"""
293293
if isinstance(x, OrderedDict):
294-
return OrderedDict((k, ordered_unbunchify(v)) for k, v in x.iteritems())
294+
return OrderedDict((k, ordered_unbunchify(v)) for k, v in x.items())
295295
elif isinstance(x, dict):
296-
return dict((k, ordered_unbunchify(v)) for k, v in x.iteritems())
296+
return dict((k, ordered_unbunchify(v)) for k, v in x.items())
297297
elif isinstance(x, (list, tuple)):
298298
return type(x)(ordered_unbunchify(v) for v in x)
299299
else:

SU2_PY/SU2/util/ordered_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __reversed__(self):
8585
def clear(self):
8686
"od.clear() -> None. Remove all items from od."
8787
try:
88-
for node in self.__map.itervalues():
88+
for node in self.__map.values():
8989
del node[:]
9090
root = self.__root
9191
root[:] = [root, root, None]

SU2_PY/SU2/util/switch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, value):
3838
def __iter__(self):
3939
"""Return the match method once, then stop"""
4040
yield self.match
41-
raise StopIteration
41+
return
4242

4343
def match(self, *args):
4444
"""Indicate whether or not to enter a case suite"""

0 commit comments

Comments
 (0)