Repository navigation
Commit fd2b2ea
committed
[geojson] Fix
`coords` was annotated `Generator[tuple[float]]`, a one-element tuple,
but it yields whole coordinate tuples:
>>> list(coords(LineString([(-115.81, 37.24), (-120.5, 40.1)])))
[(-115.81, 37.24), (-120.5, 40.1)]
>>> list(coords(Point((1.0, 2.0, 3.0))))
[(1.0, 2.0, 3.0)]
Reading the second element of a 2D coordinate therefore failed with
"Tuple index out of range". Changed to `tuple[float, ...]`.
The three `map_*` functions took `Callable[[Incomplete], float |
Geometry]`, which is wrong for `map_tuples`: the implementation calls
`tuple(func(c))`, so the callable must return an iterable of floats, and
a coordinate-swapping function was rejected. Replaced the `Incomplete`
callables with the types the implementations actually use:
- `map_coords` applies `func` to individual coordinate values
(`tuple_func` calls `func(coord[0])`, `func(coord[1])`)
- `map_tuples` applies `func` to a whole coordinate sequence and wraps
the result with `tuple(...)`
- `map_geometries` passes each geometry through `func`
Verified against geojson 3.3.0 at runtime, and with mypy --strict.coords return type and annotate map_* callables1 parent ffcf406 commit fd2b2ea
1 file changed
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
0 commit comments