Skip to content

Fix: Improve Python code quality and PEP 8 compliance#2632

Merged
pcarruscag merged 2 commits intosu2code:developfrom
shbhmexe:fix/python-code-quality
Nov 29, 2025
Merged

Fix: Improve Python code quality and PEP 8 compliance#2632
pcarruscag merged 2 commits intosu2code:developfrom
shbhmexe:fix/python-code-quality

Conversation

@shbhmexe
Copy link

@shbhmexe shbhmexe commented Nov 28, 2025

Proposed Changes

This PR addresses several code quality issues in the Python codebase to improve PEP 8 compliance and robustness.

Specific changes:

  • Improper None Comparisons: Replaced == None and != None with is None and is not None in:
    • SU2_PY/SU2_CFD.py
    • SU2_PY/parallel_computation.py
    • SU2_PY/parallel_computation_fsi.py
    • SU2_PY/topology_optimization.py
    • SU2_PY/SU2/io/data.py
  • Bare Except Clauses: Updated SU2_PY/topology_optimization.py to avoid bare except: clauses:
    • Used except OSError: for os.remove calls (handling file not found, permission errors).
    • Used except Exception: for solver execution and parsing blocks (preserving original catch-all behavior for runtime errors but allowing system interrupts like Ctrl+C to propagate).

Related Work

  • Fixes code quality issues identified during repository audit.
  • Aligns with PEP 8 style guidelines.

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I am submitting my contribution to the develop branch.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

- 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 <shubhushukla586@gmail.com>
@shbhmexe
Copy link
Author

/label code-quality

Replaces OSError with Exception in several try-except blocks to catch a broader range of errors during file operations and subprocess calls. Adds comments to clarify that file removal errors are ignored if the file does not exist.

Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
@pcarruscag pcarruscag merged commit 948a5ea into su2code:develop Nov 29, 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