Skip to content

Commit c3d8b21

Browse files
[rasterio] Accept int EPSG codes and any to_wkt provider in CRSInput (#16294)
`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.
1 parent c1b67ec commit c3d8b21

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

stubs/rasterio/rasterio/_typing.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ class _SupportsGeoInterface(Protocol):
1616
@property
1717
def __geo_interface__(self) -> Mapping[str, Any]: ...
1818

19+
@type_check_only
20+
class _SupportsToWkt(Protocol):
21+
def to_wkt(self) -> str: ...
22+
1923
# A GeoJSON-like mapping, or any object exposing one through the
2024
# `__geo_interface__` protocol (e.g. shapely / geopandas geometries).
2125
# The runtime unwraps `__geo_interface__` before use, so both forms are
2226
# accepted anywhere a geometry is expected.
2327
Geometry: TypeAlias = Mapping[str, Any] | _SupportsGeoInterface # noqa: Y047
2428
Colormap: TypeAlias = dict[int, tuple[int, int, int] | tuple[int, int, int, int]]
25-
CRSInput: TypeAlias = str | dict[str, str] | CRS
29+
# A WKT / PROJ string, an EPSG code, a PROJ dict, or any object exposing
30+
# `to_wkt` (e.g. a pyproj CRS). `CRS.from_user_input` normalizes all of them.
31+
CRSInput: TypeAlias = str | int | dict[str, str] | CRS | _SupportsToWkt
2632
FileOrBytes: TypeAlias = BinaryIO | bytes
2733
Indexes: TypeAlias = int | Sequence[int]
2834
NumType: TypeAlias = int | float

0 commit comments

Comments
 (0)