Skip to content

fix: Python 3 compatibility and C++ code quality improvements#2643

Merged
bigfooted merged 2 commits intosu2code:developfrom
shbhmexe:fix/python3-compatibility-su2py-utils
Dec 17, 2025
Merged

fix: Python 3 compatibility and C++ code quality improvements#2643
bigfooted merged 2 commits intosu2code:developfrom
shbhmexe:fix/python3-compatibility-su2py-utils

Conversation

@shbhmexe
Copy link

Proposed Changes

This PR fixes Python 2 to Python 3 compatibility issues and improves C++ code quality.

Files Modified:

Module File Changes
SU2_PY SU2/util/bunch.py .iteritems().items(), keys().sort()sorted(keys())
SU2_PY SU2/util/ordered_bunch.py .iteritems().items()
SU2_PY SU2/util/ordered_dict.py .itervalues().values()
SU2_PY SU2/io/data.py unicodestr
SU2_PY SU2/util/switch.py raise StopIterationreturn (PEP 479)
SU2_CFD src/solvers/CSpeciesFlameletSolver.cpp Remove redundant == true

Issues Fixed

Python 3 Compatibility:

Issue Impact Fix
.iteritems() removed in Py3 AttributeError Use .items()
.itervalues() removed in Py3 AttributeError Use .values()
dict.keys().sort() fails AttributeError Use sorted()
unicode type removed NameError Use str
raise StopIteration in generators RuntimeError (PEP 479) Use return

C++ Code Quality:

Issue Impact Fix
== true comparison Redundant code Direct boolean check

Related Work

This PR extends the Python 3 compatibility work started in PR #2640, addressing remaining issues in utility modules.

PR Checklist

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings.
  • My contribution is commented and consistent with SU2 style.
  • I used the pre-commit hook to prevent dirty commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation, if necessary.

…rovements

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 <shubhushukla586@gmail.com>
@bigfooted bigfooted merged commit 3261fef into su2code:develop Dec 17, 2025
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants