From 3d060225af52b7a91ff3b5917bb621c4ef068113 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Wed, 21 May 2025 13:32:12 -0400 Subject: [PATCH 1/5] Fix type hint support for 3.9 --- .python-version | 1 + src/obspec/_attributes.py | 16 +++++++++++----- src/obspec/_get.py | 7 ++++++- src/obspec/_list.py | 16 +++++++--------- src/obspec/_put.py | 9 +++++++-- 5 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..bd28b9c --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.9 diff --git a/src/obspec/_attributes.py b/src/obspec/_attributes.py index 783fc91..13be30b 100644 --- a/src/obspec/_attributes.py +++ b/src/obspec/_attributes.py @@ -1,17 +1,23 @@ from __future__ import annotations -from typing import Literal, TypeAlias +import sys +from typing import Literal, Union -Attribute: TypeAlias = ( +if sys.version_info >= (3, 10): + from typing import TypeAlias +else: + from typing_extensions import TypeAlias + +Attribute: TypeAlias = Union[ Literal[ "Content-Disposition", "Content-Encoding", "Content-Language", "Content-Type", "Cache-Control", - ] - | str -) + ], + str, +] """Additional object attribute types. - `"Content-Disposition"`: Specifies how the object should be handled by a browser. diff --git a/src/obspec/_get.py b/src/obspec/_get.py index 301f712..083fa6f 100644 --- a/src/obspec/_get.py +++ b/src/obspec/_get.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Protocol, Self, TypedDict +from typing import TYPE_CHECKING, Protocol, TypedDict if TYPE_CHECKING: import sys @@ -10,6 +10,11 @@ from ._attributes import Attributes from ._meta import ObjectMeta + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + if sys.version_info >= (3, 12): from collections.abc import Buffer else: diff --git a/src/obspec/_list.py b/src/obspec/_list.py index 061aab9..04e2d9b 100644 --- a/src/obspec/_list.py +++ b/src/obspec/_list.py @@ -1,19 +1,17 @@ from __future__ import annotations +import sys from collections.abc import Sequence -from typing import ( - Generic, - Literal, - Protocol, - Self, - TypedDict, - TypeVar, - overload, -) +from typing import Generic, Literal, Protocol, TypedDict, TypeVar, overload from ._meta import ObjectMeta from .arrow import ArrowArrayExportable, ArrowStreamExportable +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing_extensions import Self + ListChunkType_co = TypeVar( "ListChunkType_co", Sequence[ObjectMeta], diff --git a/src/obspec/_put.py b/src/obspec/_put.py index f8bdc00..c16a9db 100644 --- a/src/obspec/_put.py +++ b/src/obspec/_put.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import IO, TYPE_CHECKING, Literal, Protocol, TypeAlias, TypedDict +from typing import IO, TYPE_CHECKING, Literal, Protocol, TypedDict, Union if TYPE_CHECKING: import sys @@ -9,6 +9,11 @@ from ._attributes import Attributes + if sys.version_info >= (3, 10): + from typing import TypeAlias + else: + from typing_extensions import TypeAlias + if sys.version_info >= (3, 12): from collections.abc import Buffer else: @@ -32,7 +37,7 @@ class UpdateVersion(TypedDict, total=False): """A version indicator for the newly created object.""" -PutMode: TypeAlias = Literal["create", "overwrite"] | UpdateVersion +PutMode: TypeAlias = Union[Literal["create", "overwrite"], UpdateVersion] """Configure preconditions for the put operation There are three modes: From ea61237d33ded7ed6115c3e08042f23f5b06010d Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Wed, 21 May 2025 13:34:36 -0400 Subject: [PATCH 2/5] Add runtime requirement on typing-extensions --- pyproject.toml | 2 +- uv.lock | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9027922..e0ebf72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ license = "MIT" readme = "README.md" authors = [{ name = "Kyle Barron", email = "kyle@developmentseed.org" }] requires-python = ">=3.9" -dependencies = [] +dependencies = ["typing-extensions; python_version < '3.12'"] keywords = [] classifiers = [ "Development Status :: 4 - Beta", diff --git a/uv.lock b/uv.lock index ac329bc..7d03ca3 100644 --- a/uv.lock +++ b/uv.lock @@ -918,6 +918,9 @@ wheels = [ name = "obspec" version = "0.1.0b4" source = { editable = "." } +dependencies = [ + { name = "typing-extensions", marker = "python_full_version < '3.12'" }, +] [package.dev-dependencies] dev = [ @@ -936,6 +939,7 @@ dev = [ ] [package.metadata] +requires-dist = [{ name = "typing-extensions", marker = "python_full_version < '3.12'" }] [package.metadata.requires-dev] dev = [ From 774870796ff7836e90afe5cebaae5cf4a913ae23 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Wed, 21 May 2025 13:36:18 -0400 Subject: [PATCH 3/5] test on earlier python versions --- .github/workflows/test-python.yml | 2 +- src/obspec/_list.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 455f398..dc1ef36 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -44,7 +44,7 @@ jobs: strategy: fail-fast: true matrix: - python-version: ["3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 diff --git a/src/obspec/_list.py b/src/obspec/_list.py index 04e2d9b..fc69eb6 100644 --- a/src/obspec/_list.py +++ b/src/obspec/_list.py @@ -2,15 +2,15 @@ import sys from collections.abc import Sequence -from typing import Generic, Literal, Protocol, TypedDict, TypeVar, overload +from typing import Generic, Literal, Protocol, Self, TypedDict, TypeVar, overload from ._meta import ObjectMeta from .arrow import ArrowArrayExportable, ArrowStreamExportable -if sys.version_info >= (3, 11): - from typing import Self -else: - from typing_extensions import Self +# if sys.version_info >= (3, 11): +# from typing import Self +# else: +# from typing_extensions import Self ListChunkType_co = TypeVar( "ListChunkType_co", From 660bc6c83a237e033c96d9725174d1d34ef39488 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Wed, 21 May 2025 13:37:57 -0400 Subject: [PATCH 4/5] remove python-version file this was taking precedence over the version in CI --- .python-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .python-version diff --git a/.python-version b/.python-version deleted file mode 100644 index bd28b9c..0000000 --- a/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.9 From dae379fb2a35306b4a19275288c24785f5a5ed52 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Wed, 21 May 2025 13:39:41 -0400 Subject: [PATCH 5/5] restore correct code --- src/obspec/_list.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/obspec/_list.py b/src/obspec/_list.py index fc69eb6..04e2d9b 100644 --- a/src/obspec/_list.py +++ b/src/obspec/_list.py @@ -2,15 +2,15 @@ import sys from collections.abc import Sequence -from typing import Generic, Literal, Protocol, Self, TypedDict, TypeVar, overload +from typing import Generic, Literal, Protocol, TypedDict, TypeVar, overload from ._meta import ObjectMeta from .arrow import ArrowArrayExportable, ArrowStreamExportable -# if sys.version_info >= (3, 11): -# from typing import Self -# else: -# from typing_extensions import Self +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing_extensions import Self ListChunkType_co = TypeVar( "ListChunkType_co",