Skip to content

fix: resolve lint and type-check errors - #895

Merged
rnyb merged 3 commits into
mainfrom
fix-lint
Nov 20, 2026
Merged

rnyb merged 3 commits into
mainfrom
fix-lint

Conversation

@rnyb

@rnyb rnyb commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator
  • Guard against None restart dates in grav_subs_maps, grav_subs_points and fluxfile_obj
  • Use Sequence[datetime.datetime] for date types in restartthinner
  • Annotate Any for flux and EGRID file objects in sector2fluxnum
  • Use get_num_lgr() instead of the deprecated getNumLGR()
  • Replace cwrap.open with built-in open and drop the cwrap import
  • Remove the cwrap mypy ignore override from pyproject.toml
  • Correct the split_vectorsdatafiles return type to list Summary

- Guard against `None` restart dates in grav_subs_maps, grav_subs_points
  and fluxfile_obj
- Use `Sequence[datetime.datetime]` for date types in restartthinner
- Annotate `Any` for flux and EGRID file objects in sector2fluxnum
- Use `get_num_lgr()` instead of the deprecated `getNumLGR()`
- Replace `cwrap.open` with built-in `open` and drop the cwrap import
- Remove the `cwrap` mypy ignore override from pyproject.toml
- Correct the `split_vectorsdatafiles` return type to list `Summary`

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The restart-date guard still permits an IndexError when source_restart.dates is None, so missing dates need validation and an explicit error before indexing.

1 open issue
What changed in this PR

This PR addresses lint and type-check errors across Subscript’s simulation-data utilities by refining annotations and updating API usage.

Changes:

  • Adjust restart-date handling and date-sequence annotations.
  • Correct summary return types and annotate flux/EGRID objects.
  • Replace deprecated grid and file-opening APIs, and remove the cwrap mypy override.
File Description
src/​subscript/​summaryplot/​summaryplot.py Corrects annotations to identify returned Summary objects.
src/​subscript/​sector2fluxnum/​sector2fluxnum.py Replaces cwrap.open with built-in open.
src/​subscript/​sector2fluxnum/​fluxfile_obj.py Updates grid API calls, flux typing, and restart-date handling.
src/​subscript/​sector2fluxnum/​flux_obj.py Adds an Any alias for EGRID access.
src/​subscript/​restartthinner/​restartthinner.py Uses Sequence[datetime.datetime] for date annotations.
src/​subscript/​grav_subs_points/​grav_subs_points.py Allows iteration when restart dates are None.
src/​subscript/​grav_subs_maps/​grav_subs_maps.py Allows iteration when restart dates are None.
pyproject.toml Removes the cwrap missing-import override.

Review effort: Balanced

- Replace silent fallback to an empty list with an explicit ValueError
- Avoid an IndexError when accessing the first restart date

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the lint and type-check updates to the simulation-data utilities.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@rnyb
rnyb requested a review from alifbe November 20, 2026 12:00
@codecov-commenter

codecov-commenter commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.47%. Comparing base (46a9e23) to head (7c868b8).

Files with missing lines Patch % Lines
src/subscript/sector2fluxnum/fluxfile_obj.py 68.42% 12 Missing ⚠️
src/subscript/sector2fluxnum/flux_obj.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #895      +/-   ##
==========================================
- Coverage   84.47%   84.47%   -0.01%     
==========================================
  Files          49       49              
  Lines        7570     7574       +4     
==========================================
+ Hits         6395     6398       +3     
- Misses       1175     1176       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Replace index access on EGRID and flux files with iget_kw calls
- Drop the Any type annotations that were hiding typing errors
- Cache the keyword in kw_fine within the flux writing loop

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the annotation fixes, missing-date handling, and library-call updates.

No open issues 🎉

Review effort: Balanced

@rnyb
rnyb requested a review from alifbe November 20, 2026 12:58
Comment thread pyproject.toml
"ert",
"grid3d_maps.*",
"fmu.tools.*",
"cwrap",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you know why we used cwrap before and why it is failing now?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

cwrap is a Python library for wrapping C code through ctypes. In older resdata, which came from the ecl library, the Python classes called C functions through it. The C code wrote GRDECL files through a C FILE*, so a normal Python file handle wouldn't work. cwrap.open() returns a file object that exposes the underlying FILE*. That's why subscript used it for write_grdecl (it's been there since at least b6c2e076).

It fails now because resdata 7 reimplemented the I/O in Python and compiled extension modules. write_grdecl and read_grdecl now take ordinary io.TextIOWrapper handles, and cwrap is no longer in resdata's dependencies. Nothing else installs it, so the CI environment lacks it and the import fails.

@alifbe alifbe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great job 💯

@rnyb
rnyb merged commit 0e4970f into main Nov 20, 2026
11 checks passed
@rnyb
rnyb deleted the fix-lint branch November 20, 2026 13:34
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.

4 participants