Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .github/workflows/run_checks_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
version: 0.13.6 # uv version
python-version: "3.15"

# use latest mypy version here, (even though pinned to 1.19.1 in lint group for Python 3.9 support)
- name: Run mypy --strict
run: uvx mypy --strict ./src/shapefile.py

Expand All @@ -63,22 +62,15 @@ jobs:
"3.12",
"3.11",
"3.10",
"3.9",
]
os: [
"ubuntu-latest",
]
exclude:
- python-version: "3.9"
os: "ubuntu-latest"

include:
- python-version: "3.15"
os: "windows-latest"
- python-version: "3.15"
os: "macos-latest"
- python-version: "3.9"
os: "ubuntu-24.04"

runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -109,20 +101,12 @@ jobs:
"3.12",
"3.11",
"3.10",
"3.9",
]
os: [
"ubuntu-latest",
"windows-latest",
]
exclude:
- python-version: "3.9"
os: "ubuntu-latest"
include:
- python-version: "3.9"
os: "ubuntu-24.04"
- python-version: "3.9"
os: "ubuntu-24.04"
- python-version: "3.15"
os: "macos-latest"

Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/speed_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,13 @@ jobs:
fail-fast: false
matrix:
python-version: [
"3.9",
"3.10",
"3.15",
]
os: [
"ubuntu-latest",
"windows-latest",
]
exclude:
- python-version: "3.9"
os: "ubuntu-latest"
include:
- python-version: "3.9"
os: "ubuntu-24.04"


runs-on: ${{ matrix.os }}
steps:
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description = "Pure Python read/write support for ESRI Shapefile format"
license = "MIT"
license-files = ["LICENSE.TXT"]
dynamic = ["version"]
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
Expand All @@ -37,8 +37,8 @@ dev = [
{include-group = "test"}
]
lint = [
"mypy==1.19.1", # last to support Python 3.9
'pre-commit; python_version >= "3.10"',
"mypy==2.4.1",
'pre-commit',
"ruff",
"pre-commit-hooks",
]
Expand Down
62 changes: 27 additions & 35 deletions src/shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Provides read and write support for ESRI Shapefiles.
authors: jlawhead<at>geospatialpython.com
maintainers: james<at>jamesparrott.dev and karim.bahgat.norway<at>gmail.com
Compatible with Python versions >=3.9
Compatible with Python versions >=3.10
"""

from __future__ import annotations
Expand Down Expand Up @@ -36,12 +36,10 @@
Generic,
Literal,
NamedTuple,
Optional,
Protocol,
SupportsIndex,
TypedDict,
TypeVar,
Union,
cast,
overload,
runtime_checkable,
Expand Down Expand Up @@ -118,13 +116,13 @@
T = TypeVar("T")
Point2D = tuple[float, float]
Point3D = tuple[float, float, float]
PointMT = tuple[float, float, Optional[float]]
PointZT = tuple[float, float, float, Optional[float]]
PointMT = tuple[float, float, float | None]
PointZT = tuple[float, float, float, float | None]

Coord = Union[Point2D, Point3D]
Coord = Point2D | Point3D
Coords = list[Coord]

PointT = Union[Point2D, PointMT, PointZT]
PointT = Point2D | PointMT | PointZT
PointsT = list[PointT]


Expand Down Expand Up @@ -253,8 +251,8 @@ def read(self, size: int = -1) -> bytes: ...


# File name, file object or anything with a read() method that returns bytes.
BinaryFileT = Union[str, PathLike[Any], IO[bytes]]
BinaryFileStreamT = Union[IO[bytes], io.BytesIO, WriteSeekableBinStream]
BinaryFileT = str | PathLike[Any] | IO[bytes]
BinaryFileStreamT = IO[bytes] | io.BytesIO | WriteSeekableBinStream

FieldTypeT = Literal["C", "D", "F", "L", "M", "N"]

Expand Down Expand Up @@ -738,10 +736,10 @@ def __repr__(self) -> str:
return f'Field(name="{self.name}", field_type=FieldType.{self.field_type}, size={self.size}, decimal={self.decimal})'


RecordValueNotDate = Union[bool, int, float, str]
RecordValueNotDate = bool | int | float | str

# A Possible value in a Shapefile dbf record, i.e. L, N, M, F, C, or D types
RecordValue = Union[RecordValueNotDate, date]
RecordValue = RecordValueNotDate | date


@runtime_checkable
Expand Down Expand Up @@ -789,14 +787,14 @@ class GeoJSONMultiPolygon(TypedDict):
coordinates: list[list[PointsT]]


GeoJSONHomogeneousGeometryObject = Union[
GeoJSONPoint,
GeoJSONMultiPoint,
GeoJSONLineString,
GeoJSONMultiLineString,
GeoJSONPolygon,
GeoJSONMultiPolygon,
]
GeoJSONHomogeneousGeometryObject = (
GeoJSONPoint
| GeoJSONMultiPoint
| GeoJSONLineString
| GeoJSONMultiLineString
| GeoJSONPolygon
| GeoJSONMultiPolygon
)

GEOJSON_TO_SHAPETYPE: dict[str, int] = {
"Null": NULL,
Expand All @@ -815,7 +813,7 @@ class GeoJSONGeometryCollection(TypedDict):


# RFC7946 3.1
GeoJSONObject = Union[GeoJSONHomogeneousGeometryObject, GeoJSONGeometryCollection]
GeoJSONObject = GeoJSONHomogeneousGeometryObject | GeoJSONGeometryCollection


class GeoJSONFeature(TypedDict):
Expand Down Expand Up @@ -2628,9 +2626,7 @@ def __getitem__(
:return: the value of the field
"""
try:
# Using | on types in Python 3.9 also raises TypeError, so
# Union is needed, as we subsequently catch TypeError.
return list.__getitem__(self, cast(Union[SupportsIndex, slice], item))
return list.__getitem__(self, cast(SupportsIndex | slice, item))
except TypeError:
try:
index = self._field_positions[cast(str, item)]
Expand Down Expand Up @@ -2660,9 +2656,9 @@ def __setitem__(
:param key: Either the position of the value or the name of a field
:param value: the new value of the field
"""
ValidKVTuple = Union[
tuple[SupportsIndex, RecordValue], tuple[slice, Iterable[RecordValue]]
]
ValidKVTuple = (
tuple[SupportsIndex, RecordValue] | tuple[slice, Iterable[RecordValue]]
)
try:
list.__setitem__(self, *cast(ValidKVTuple, (key, value)))
return
Expand Down Expand Up @@ -2704,9 +2700,7 @@ def __dir__(self) -> list[str]:
default = list(
dir(type(self))
) # default list methods and attributes of this class
fnames = list(
self._field_positions.keys()
) # plus field names (random order if Python version < 3.6)
fnames = list(self._field_positions.keys()) # plus field names
return default + fnames

def __eq__(self, other: Any) -> bool:
Expand Down Expand Up @@ -2737,7 +2731,7 @@ def __geo_interface__(self) -> GeoJSONFeature:
}


class Shapes(list[Optional[Shape]]):
class Shapes(list[Shape | None]):
"""A class to hold a list of Shape objects. Subclasses list to ensure compatibility with
former work and to reuse all the optimizations of the builtin list.
In addition to the list interface, this also provides the GeoJSON __geo_interface__
Expand Down Expand Up @@ -2932,9 +2926,7 @@ def close(self) -> None:
self.exit_stack.close()


FileObjT = TypeVar(
"FileObjT", bound=Union[ReadSeekableBinStream, WriteSeekableBinStream]
)
FileObjT = TypeVar("FileObjT", bound=ReadSeekableBinStream | WriteSeekableBinStream)


@dataclass(frozen=True)
Expand Down Expand Up @@ -5070,10 +5062,10 @@ def _shp_record(self, s: Shape) -> tuple[int, int]:
self._update_file_bbox(s)

if s.shapeType in PointM_shapeTypes | _HasM_shapeTypes:
self._update_file_mbox(cast(Union[_HasM, PointM], s))
self._update_file_mbox(cast(_HasM | PointM, s))

if s.shapeType in PointZ_shapeTypes | _HasZ_shapeTypes:
self._update_file_zbox(cast(Union[_HasZ, PointZ], s))
self._update_file_zbox(cast(_HasZ | PointZ, s))

# Create an in-memory binary buffer to avoid
# unnecessary seeks to files on disk
Expand Down
Loading
Loading