Skip to content

fix: Python 3 correctness and PEP 8 compliance improvements - #2640

Merged
pcarruscag merged 5 commits into
su2code:developfrom
shbhmexe:bugfix/su2py-correctness-tools
Dec 9, 2025
Merged

fix: Python 3 correctness and PEP 8 compliance improvements#2640
pcarruscag merged 5 commits into
su2code:developfrom
shbhmexe:bugfix/su2py-correctness-tools

Conversation

@shbhmexe

@shbhmexe shbhmexe commented Dec 8, 2025

Copy link
Copy Markdown

This PR fixes Python code quality issues in SU2_PY without changing behavior.

None Comparisons (PEP 8 E711)

Fixed improper None comparisons using identity operators:

  • not x is Nonex is not None (interface.py, state.py)
  • == Noneis None (SU2_CFD.py, parallel_computation.py, data.py, topology_optimization.py)
  • != Noneis not None (SU2_CFD.py, data.py)

Bare Except Clauses (PEP 8 E722)

Replaced bare except: with specific exceptions in topology_optimization.py:

  • except OSError: for file removal operations
  • except Exception: for general error handling

Deprecated Python 2 Methods

  • .has_key(key)key in dict (data.py)
  • .iteritems().items() (data.py)

Mutable Default Arguments

Fixed shared-state bugs by replacing mutable defaults with None:

  • restart2solution(state={})restart2solution(state=None)
  • projection(state={})projection(state=None)
  • tecplot(keys_plot=[])tecplot(keys_plot=None)

Files Modified (10 files)

data.py, state.py, tools.py, interface.py, projection.py, plot.py, SU2_CFD.py, parallel_computation.py, parallel_computation_fsi.py, topology_optimization.py

- Use identity operators for None comparisons (is/is not)
- Replace bare except with Exception/OSError
- Replace .has_key() and .iteritems() with Python 3 equivalents
- Fix mutable default arguments in function signatures

Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
Comment thread SU2_PY/topology_optimization.py Fixed
Comment thread SU2_PY/topology_optimization.py Fixed
Comment thread SU2_PY/topology_optimization.py Fixed
@shbhmexe

shbhmexe commented Dec 8, 2025

Copy link
Copy Markdown
Author

/label changelog:chore

Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
Comment thread SU2_PY/topology_optimization.py Fixed
Comment thread SU2_PY/topology_optimization.py Fixed
Comment thread SU2_PY/topology_optimization.py Fixed
Comment thread externals/opdi
Comment thread SU2_PY/SU2/io/tools.py Outdated
Comment thread SU2_PY/SU2/run/projection.py
@pcarruscag
pcarruscag changed the base branch from master to develop December 9, 2025 01:02
Comment thread SU2_PY/topology_optimization.py Fixed
Comment thread SU2_PY/topology_optimization.py Fixed
Comment thread SU2_PY/topology_optimization.py Fixed
shbhmexe added 2 commits December 9, 2025 15:01
….projection

- tools.py: update restart2solution docstring to match signature (state=None), per review.
- projection.py: clarify that the 'state' parameter is accepted for API compatibility and currently unused.
- No functional changes.

Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
…odeQL/CodeFactor)

- Replace three `try/except ...: pass` blocks with existence checks before os.remove.
- No behavioral change; resolves “Unreachable except block” and “Empty except” findings.

Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
@pcarruscag
pcarruscag merged commit e27908e into su2code:develop Dec 9, 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