Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: apply suggestions from pyupgrade #2361

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

mwtoews
Copy link
Contributor

@mwtoews mwtoews commented Nov 11, 2024

This PR refactors the codebase with Ruff's pyupgrade check, based on pyupgrade. Not all suggestions are applied, and some manual edits were applied in addition to the affected code. Removing target-version from the ruff options allows this to be automatically evaluated from pyproject.toml.

The rules that were applied include:

  • UP004 (useless-object-inheritance)
  • UP006 (non-pep585-annotation) - see PEP 585 for details; this was not applied to get_modflow.py to maintain it's compatibility for older Python versions in stand-alone mode
  • UP018 (native-literals)
  • UP034 (extraneous-parentheses)
  • UP035 (deprecated-import)

Meanwhile, these rules were somewhat ignored:

  • UP031,UP032: related to upgrading to f-strings. Ignored since these could involve much more string and message related refactoring to adjacent code. However, a few upgraded f-strings are upgraded where it looks simple, and in user-facing docs.
  • UP015: for redundant file modes. Kept default file modes (e.g. open(..., "r") to keep it more clear, e.g. when a file pointer object is left open for reading (and then closed many lines further down, as is often done with legacy flopy code)

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 4 lines in your changes missing coverage. Please review.

Project coverage is 74.2%. Comparing base (acc5a5b) to head (4bf8452).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
flopy/mf6/mfpackage.py 0.0% 1 Missing ⚠️
flopy/mf6/utils/model_splitter.py 50.0% 1 Missing ⚠️
flopy/modflow/mfmnw1.py 75.0% 1 Missing ⚠️
flopy/modflow/mfpbc.py 0.0% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #2361    +/-   ##
========================================
  Coverage     74.1%   74.2%            
========================================
  Files          292     292            
  Lines        59476   59622   +146     
========================================
+ Hits         44127   44261   +134     
- Misses       15349   15361    +12     
Files with missing lines Coverage Δ
flopy/export/netcdf.py 49.2% <100.0%> (ø)
flopy/export/shapefile_utils.py 84.0% <100.0%> (+0.3%) ⬆️
flopy/mbase.py 72.1% <100.0%> (+<0.1%) ⬆️
flopy/mf6/mfsimbase.py 75.3% <100.0%> (+0.1%) ⬆️
flopy/mfusg/mfusgdisu.py 83.8% <ø> (+<0.1%) ⬆️
flopy/mfusg/mfusgsms.py 98.1% <ø> (+<0.1%) ⬆️
flopy/modflow/mfrch.py 95.9% <ø> (+<0.1%) ⬆️
flopy/modflow/mfsfr2.py 87.3% <ø> (-0.1%) ⬇️
flopy/modflow/mfstr.py 78.9% <ø> (+0.1%) ⬆️
flopy/modflow/mfswi2.py 63.7% <ø> (+0.2%) ⬆️
... and 21 more

... and 57 files with indirect coverage changes

Copy link
Member

@wpbonelli wpbonelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UP031,UP032: related to upgrading to f-strings. Ignored since these could involve much more string and message related refactoring to adjacent code. However, a few upgraded f-strings are upgraded where it looks simple, and in user-facing docs.

UP015: for redundant file modes. Kept default file modes (e.g. open(..., "r") to keep it more clear, e.g. when a file pointer object is left open for reading (and then closed many lines further down, as is often done with legacy flopy code)

We should keep these in mind going forward.. Probably not worth any extra attention in the legacy flopy.mf6 since that will get a rewrite anyway, but elsewhere legacy code could be gradually updated as we find time

@wpbonelli wpbonelli merged commit a5545c6 into modflowpy:develop Nov 11, 2024
23 checks passed
@mwtoews mwtoews deleted the pyupgrade branch November 11, 2024 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants