[rasterio] Accept int EPSG codes and any to_wkt provider in CRSInput - #16294
Open
thomas-maschler wants to merge 1 commit into
Open
[rasterio] Accept int EPSG codes and any to_wkt provider in CRSInput#16294thomas-maschler wants to merge 1 commit into
thomas-maschler wants to merge 1 commit into
Conversation
`CRS.from_user_input` dispatches on a `to_wkt` method before checking any concrete type, and reads a bare `int` as an EPSG code. Model the former as a `_SupportsToWkt` Protocol rather than taking a dependency on pyproj.
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Contributor
|
Great turnaround @thomas-maschler. This does just the job and does allow a |
jack-volantautonomy
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #16136
CRS.from_user_inputnormalizes everyCRSInputvalue, and it accepts two forms the alias didn't cover: any object with ato_wktmethod, checked before any concrete type, which is what makespyproj.CRSwork; and a bareint, read as an EPSG code viaCRS.from_epsg.The reported false positives (
transform_bounds,reproject,MemoryFile.openwith apyproj.CRS) come from the first. I modelled it as a_SupportsToWktProtocol rather than addingpyproj.CRSto the union, matching how_SupportsGeoInterfacealready handles shapely and geopandas geometries:to_wktrasterio.crs.CRSandpyproj.CRScompare equal but hash differently, so they're better kept as distinct typesEvery current
CRSInputcall site normalizes throughfrom_user_input(including_can_create_osr, thegcpssetter, andcalculate_default_transform), so widening with int is safe throughout._transform_boundsand friends keep theirCRSannotation, since those Cython signatures are statically typed and do reject anything else.Added
@tests/test_cases/check_crs_input.pycovering the accepted forms and confirming an object withoutto_wktis still rejected.