Reason or Problem
xrspatial.geotiff._sources._FileSource exposes close() but no __enter__ / __exit__. Every call site has to wrap it in try / finally to guarantee mmap release. PR #2448 added another such call site in _vrt_validation._check_mixed_source_crs, and a code-review nit flagged the resulting try / except / finally / continue shape as harder to scan than a with block.
Proposal
Add __enter__ / __exit__ to _FileSource so callers can write:
with _FileSource(path) as src:
data = src.read_all()
...
Then sweep the existing call sites (search for _FileSource( in xrspatial/geotiff/) and replace each try / finally with a with block. The mmap-cache release semantics stay the same; the helper change is mechanical.
Drawbacks
Mechanical sweep across several files. Worth verifying that no call site relies on the handle outliving a function scope before swapping wholesale.
Additional Notes or Context
Surfaced during review of PR #2448. Not blocking that PR; tracked here so the cleanup is not forgotten.
Reason or Problem
xrspatial.geotiff._sources._FileSourceexposesclose()but no__enter__/__exit__. Every call site has to wrap it intry/finallyto guarantee mmap release. PR #2448 added another such call site in_vrt_validation._check_mixed_source_crs, and a code-review nit flagged the resultingtry/except/finally/continueshape as harder to scan than awithblock.Proposal
Add
__enter__/__exit__to_FileSourceso callers can write:Then sweep the existing call sites (search for
_FileSource(inxrspatial/geotiff/) and replace eachtry/finallywith awithblock. The mmap-cache release semantics stay the same; the helper change is mechanical.Drawbacks
Mechanical sweep across several files. Worth verifying that no call site relies on the handle outliving a function scope before swapping wholesale.
Additional Notes or Context
Surfaced during review of PR #2448. Not blocking that PR; tracked here so the cleanup is not forgotten.