Skip to content

Commit cf15bb1

Browse files
committed
deps!(python): drop Python 3.9 support
1 parent 9ac8d63 commit cf15bb1

29 files changed

Lines changed: 235 additions & 403 deletions

.github/workflows/build.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
- name: Set up Python
7878
uses: actions/setup-python@v6
7979
with:
80-
python-version: "3.9 - 3.14"
80+
python-version: "3.10 - 3.14"
8181
update-environment: true
8282

8383
- name: Upgrade pip
@@ -146,7 +146,6 @@ jobs:
146146
- { runner: windows-latest, platform: windows, archs: "auto32" }
147147
- { runner: windows-11-arm, platform: windows, archs: "ARM64" }
148148
python-version:
149-
- "3.9"
150149
- "3.10"
151150
- "3.11"
152151
- "3.12"
@@ -157,8 +156,6 @@ jobs:
157156
- "pypy-3.11"
158157
exclude:
159158
# Exclude unsupported Python versions
160-
- python-version: "3.9"
161-
target: { archs: "ARM64" }
162159
- python-version: "3.10"
163160
target: { archs: "ARM64" }
164161
- python-version: "pypy-3.11"
@@ -387,7 +384,7 @@ jobs:
387384
if: startsWith(github.ref, 'refs/tags/')
388385
uses: actions/setup-python@v6
389386
with:
390-
python-version: "3.9 - 3.14"
387+
python-version: "3.10 - 3.14"
391388
update-environment: true
392389

393390
- name: Upgrade pip

.github/workflows/tests-with-pydebug.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,13 @@ jobs:
6767
matrix:
6868
runner: [ubuntu-latest, macos-latest, windows-latest]
6969
python-version:
70-
- "3.9"
7170
- "3.10"
7271
- "3.11"
7372
- "3.12"
7473
- "3.13"
7574
- "3.14"
7675
python-abiflags: ["d", "td"]
7776
exclude:
78-
- python-version: "3.9"
79-
python-abiflags: "td"
8077
- python-version: "3.10"
8178
python-abiflags: "td"
8279
- python-version: "3.11"

.github/workflows/tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ jobs:
6666
matrix:
6767
runner: [ubuntu-latest, macos-latest, windows-latest]
6868
python-version:
69-
- "3.9"
7069
- "3.10"
7170
- "3.11"
7271
- "3.12"

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ python3 -m cibuildwheel --platform=linux --output-dir=wheelhouse --config-file=p
8888
It will build wheel binaries for all supported CPython versions. The outputs will be placed in the `wheelhouse` directory.
8989

9090
To build a wheel for a specific CPython version, you can use the [`CIBW_BUILD`](https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip) environment variable.
91-
For example, the following command will build a wheel for Python 3.9:
91+
For example, the following command will build a wheel for Python 3.10:
9292

9393
```bash
94-
CIBW_BUILD="cp39*manylinux*" python3 -m cibuildwheel --platform=linux --output-dir=wheelhouse --config-file=pyproject.toml
94+
CIBW_BUILD="cp310*manylinux*" python3 -m cibuildwheel --platform=linux --output-dir=wheelhouse --config-file=pyproject.toml
9595
```
9696

97-
You can change `cp39*` to `cp312*` to build for Python 3.12. See <https://cibuildwheel.readthedocs.io/en/stable/options> for more options.
97+
You can change `cp310*` to `cp312*` to build for Python 3.12. See <https://cibuildwheel.readthedocs.io/en/stable/options> for more options.
9898

9999
## Documentation
100100

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# OpTree
44

5-
![Python 3.9+](https://img.shields.io/badge/Python-3.9%2B-brightgreen)
5+
![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-brightgreen)
66
[![PyPI](https://img.shields.io/pypi/v/optree?logo=pypi)](https://pypi.org/project/optree)
77
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/metaopt/optree/build.yml?label=build&logo=github)
88
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/metaopt/optree/tests.yml?label=tests&logo=github)
@@ -71,7 +71,7 @@ export pybind11_DIR="/path/to/custom/pybind11"
7171
pip3 install .
7272
```
7373

74-
Compiling from the source requires Python 3.9+, a compiler (`gcc` / `clang` / `icc` / `cl.exe`) that supports C++20 and a `cmake` installation.
74+
Compiling from the source requires Python 3.10+, a compiler (`gcc` / `clang` / `icc` / `cl.exe`) that supports C++20 and a `cmake` installation.
7575

7676
--------------------------------------------------------------------------------
7777

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ def typehints_formatter(annotation, config=None):
228228
import optree
229229

230230
if (
231-
isinstance(annotation, type(typing.Union[int, str]))
232-
and typing.get_origin(annotation) is typing.Union
231+
isinstance(annotation, type(int | str))
232+
and typing.get_origin(annotation) is type(int | str)
233233
and annotation in optree.PyTree.__instances__
234234
):
235235
param, name = optree.PyTree.__instances__[annotation]

include/optree/pymacros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ limitations under the License.
2323

2424
#include <pybind11/pybind11.h>
2525

26-
#if !(defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x03090000) // Python 3.9
27-
# error "Python 3.9 or newer is required."
26+
#if !(defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x030A0000) // Python 3.10
27+
# error "Python 3.10 or newer is required."
2828
#endif
2929

3030
#if !(defined(PYBIND11_VERSION_HEX) && PYBIND11_VERSION_HEX >= 0x020C00F0) // pybind11 2.12.0

optree/accessors.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import annotations
1818

1919
import dataclasses
20-
import sys
2120
from collections.abc import Iterable, Mapping, Sequence
2221
from typing import TYPE_CHECKING, Any, ClassVar, Generic, Literal, TypeVar, overload
2322
from typing_extensions import Self # Python 3.11+
@@ -47,10 +46,7 @@
4746
]
4847

4948

50-
SLOTS = {'slots': True} if sys.version_info >= (3, 10) else {} # Python 3.10+
51-
52-
53-
@dataclasses.dataclass(init=True, repr=False, eq=False, frozen=True, **SLOTS)
49+
@dataclasses.dataclass(init=True, repr=False, eq=False, frozen=True, slots=True)
5450
class PyTreeEntry:
5551
"""Base class for path entries."""
5652

@@ -122,9 +118,6 @@ def codify(self, /, node: str = '') -> str:
122118
return f'{node}[<flat index {self.entry!r}>]' # should be overridden
123119

124120

125-
del SLOTS
126-
127-
128121
_T = TypeVar('_T')
129122
_T_co = TypeVar('_T_co', covariant=True)
130123
_KT_co = TypeVar('_KT_co', covariant=True)
@@ -134,8 +127,6 @@ def codify(self, /, node: str = '') -> str:
134127
class AutoEntry(PyTreeEntry):
135128
"""A generic path entry class that determines the entry type on creation automatically."""
136129

137-
__slots__: ClassVar[tuple[()]] = ()
138-
139130
def __new__( # type: ignore[misc]
140131
cls,
141132
/,
@@ -184,8 +175,6 @@ def __new__( # type: ignore[misc]
184175
class GetItemEntry(PyTreeEntry):
185176
"""A generic path entry class for nodes that access their children by :meth:`__getitem__`."""
186177

187-
__slots__: ClassVar[tuple[()]] = ()
188-
189178
def __call__(self, obj: Any, /) -> Any:
190179
"""Get the child object."""
191180
return obj[self.entry]
@@ -198,8 +187,6 @@ def codify(self, /, node: str = '') -> str:
198187
class GetAttrEntry(PyTreeEntry):
199188
"""A generic path entry class for nodes that access their children by :meth:`__getattr__`."""
200189

201-
__slots__: ClassVar[tuple[()]] = ()
202-
203190
entry: str
204191

205192
@property
@@ -219,14 +206,10 @@ def codify(self, /, node: str = '') -> str:
219206
class FlattenedEntry(PyTreeEntry): # pylint: disable=too-few-public-methods
220207
"""A fallback path entry class for flattened objects."""
221208

222-
__slots__: ClassVar[tuple[()]] = ()
223-
224209

225210
class SequenceEntry(GetItemEntry, Generic[_T_co]):
226211
"""A path entry class for sequences."""
227212

228-
__slots__: ClassVar[tuple[()]] = ()
229-
230213
entry: int
231214
type: builtins.type[Sequence[_T_co]]
232215

@@ -247,8 +230,6 @@ def __repr__(self, /) -> str:
247230
class MappingEntry(GetItemEntry, Generic[_KT_co, _VT_co]):
248231
"""A path entry class for mappings."""
249232

250-
__slots__: ClassVar[tuple[()]] = ()
251-
252233
entry: _KT_co
253234
type: builtins.type[Mapping[_KT_co, _VT_co]]
254235

@@ -269,8 +250,6 @@ def __repr__(self, /) -> str:
269250
class NamedTupleEntry(SequenceEntry[_T]):
270251
"""A path entry class for namedtuple objects."""
271252

272-
__slots__: ClassVar[tuple[()]] = ()
273-
274253
entry: int
275254
type: builtins.type[NamedTuple[_T]] # type: ignore[type-arg]
276255
kind: Literal[PyTreeKind.NAMEDTUPLE]
@@ -299,8 +278,6 @@ def codify(self, /, node: str = '') -> str:
299278
class StructSequenceEntry(SequenceEntry[_T]):
300279
"""A path entry class for PyStructSequence objects."""
301280

302-
__slots__: ClassVar[tuple[()]] = ()
303-
304281
entry: int
305282
type: builtins.type[StructSequence[_T]]
306283
kind: Literal[PyTreeKind.STRUCTSEQUENCE]
@@ -329,8 +306,6 @@ def codify(self, /, node: str = '') -> str:
329306
class DataclassEntry(GetAttrEntry):
330307
"""A path entry class for dataclasses."""
331308

332-
__slots__: ClassVar[tuple[()]] = ()
333-
334309
entry: str | int # type: ignore[assignment]
335310

336311
@property

0 commit comments

Comments
 (0)