Skip to content

Commit 6014918

Browse files
authored
Update Python version requirement to 3.9 in accordance with NEP 29 (#418)
* Bump minimal Python to ≥3.8 * Drop support for 3.8
1 parent 0936a93 commit 6014918

14 files changed

+41
-50
lines changed

.github/workflows/nox.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
platform: [ubuntu-latest, macos-latest, windows-latest]
15-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
15+
python-version: ["3.9", "3.10", "3.11"]
1616

1717
steps:
1818
- uses: actions/checkout@v3

adaptive/learner/average_learner1D.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import math
44
import sys
55
from collections import defaultdict
6+
from collections.abc import Iterable, Sequence
67
from copy import deepcopy
78
from math import hypot
8-
from typing import Callable, DefaultDict, Iterable, List, Sequence, Tuple
9+
from typing import Callable
910

1011
import numpy as np
1112
import scipy.stats
@@ -25,8 +26,8 @@
2526
except ModuleNotFoundError:
2627
with_pandas = False
2728

28-
Point = Tuple[int, Real]
29-
Points = List[Point]
29+
Point = tuple[int, Real]
30+
Points = list[Point]
3031

3132
__all__: list[str] = ["AverageLearner1D"]
3233

@@ -504,7 +505,7 @@ def tell_many( # type: ignore[override]
504505
)
505506

506507
# Create a mapping of points to a list of samples
507-
mapping: DefaultDict[Real, DefaultDict[Int, Real]] = defaultdict(
508+
mapping: defaultdict[Real, defaultdict[Int, Real]] = defaultdict(
508509
lambda: defaultdict(dict)
509510
)
510511
for (seed, x), y in zip(xs, ys):

adaptive/learner/balancing_learner.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import itertools
44
import sys
55
from collections import defaultdict
6-
from collections.abc import Iterable
6+
from collections.abc import Iterable, Sequence
77
from contextlib import suppress
88
from functools import partial
99
from operator import itemgetter
10-
from typing import Any, Callable, Dict, Sequence, Tuple, Union, cast
10+
from typing import Any, Callable, Union, cast
1111

1212
import numpy as np
1313

@@ -21,10 +21,7 @@
2121
else:
2222
from typing_extensions import TypeAlias
2323

24-
if sys.version_info >= (3, 8):
25-
from typing import Literal
26-
else:
27-
from typing_extensions import Literal
24+
from typing import Literal
2825

2926
try:
3027
import pandas
@@ -42,8 +39,8 @@ def dispatch(child_functions: list[Callable], arg: Any) -> Any:
4239
STRATEGY_TYPE: TypeAlias = Literal["loss_improvements", "loss", "npoints", "cycle"]
4340

4441
CDIMS_TYPE: TypeAlias = Union[
45-
Sequence[Dict[str, Any]],
46-
Tuple[Sequence[str], Sequence[Tuple[Any, ...]]],
42+
Sequence[dict[str, Any]],
43+
tuple[Sequence[str], Sequence[tuple[Any, ...]]],
4744
None,
4845
]
4946

adaptive/learner/base_learner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import abc
44
from contextlib import suppress
5-
from typing import TYPE_CHECKING, Any, Callable, Dict, TypeVar
5+
from typing import TYPE_CHECKING, Any, Callable, TypeVar
66

77
import cloudpickle
88

@@ -66,7 +66,7 @@ def _wrapped(loss_per_interval):
6666
return _wrapped
6767

6868

69-
DataType = Dict[Any, Any]
69+
DataType = dict[Any, Any]
7070

7171

7272
class BaseLearner(abc.ABC):

adaptive/learner/integrator_coeffs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from collections import defaultdict
55
from fractions import Fraction
6-
from functools import lru_cache
6+
from functools import cache
77

88
import numpy as np
99
import scipy.linalg
@@ -143,7 +143,7 @@ def calc_V(x: np.ndarray, n: int) -> np.ndarray:
143143
return np.array(V).T
144144

145145

146-
@lru_cache(maxsize=None)
146+
@cache
147147
def _coefficients():
148148
"""Compute the coefficients on demand, in order to avoid doing linear algebra on import."""
149149
eps = np.spacing(1)

adaptive/learner/learner1D.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import itertools
55
import math
66
import sys
7+
from collections.abc import Sequence
78
from copy import copy, deepcopy
8-
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Sequence, Tuple, Union
9+
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
910

1011
import cloudpickle
1112
import numpy as np
@@ -41,27 +42,27 @@
4142
# -- types --
4243

4344
# Commonly used types
44-
Interval: TypeAlias = Union[Tuple[float, float], Tuple[float, float, int]]
45-
NeighborsType: TypeAlias = SortedDict[float, List[Optional[float]]]
45+
Interval: TypeAlias = Union[tuple[float, float], tuple[float, float, int]]
46+
NeighborsType: TypeAlias = SortedDict[float, list[Optional[float]]]
4647

4748
# Types for loss_per_interval functions
48-
XsType0: TypeAlias = Tuple[float, float]
49-
YsType0: TypeAlias = Union[Tuple[float, float], Tuple[np.ndarray, np.ndarray]]
50-
XsType1: TypeAlias = Tuple[
49+
XsType0: TypeAlias = tuple[float, float]
50+
YsType0: TypeAlias = Union[tuple[float, float], tuple[np.ndarray, np.ndarray]]
51+
XsType1: TypeAlias = tuple[
5152
Optional[float], Optional[float], Optional[float], Optional[float]
5253
]
5354
YsType1: TypeAlias = Union[
54-
Tuple[Optional[float], Optional[float], Optional[float], Optional[float]],
55-
Tuple[
55+
tuple[Optional[float], Optional[float], Optional[float], Optional[float]],
56+
tuple[
5657
Optional[np.ndarray],
5758
Optional[np.ndarray],
5859
Optional[np.ndarray],
5960
Optional[np.ndarray],
6061
],
6162
]
62-
XsTypeN: TypeAlias = Tuple[Optional[float], ...]
63+
XsTypeN: TypeAlias = tuple[Optional[float], ...]
6364
YsTypeN: TypeAlias = Union[
64-
Tuple[Optional[float], ...], Tuple[Optional[np.ndarray], ...]
65+
tuple[Optional[float], ...], tuple[Optional[np.ndarray], ...]
6566
]
6667

6768

adaptive/learner/learner2D.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import itertools
44
import warnings
55
from collections import OrderedDict
6+
from collections.abc import Iterable
67
from copy import copy
78
from math import sqrt
8-
from typing import Callable, Iterable
9+
from typing import Callable
910

1011
import cloudpickle
1112
import numpy as np

adaptive/learner/learnerND.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def _get_iso(self, level=0.0, which="surface"):
11111111
vertices = [] # index -> (x,y,z)
11121112
faces_or_lines = [] # tuple of indices of the corner points
11131113

1114-
@functools.lru_cache()
1114+
@functools.lru_cache
11151115
def _get_vertex_index(a, b):
11161116
vertex_a = self.tri.vertices[a]
11171117
vertex_b = self.tri.vertices[b]

adaptive/learner/sequence_learner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44
from copy import copy
5-
from typing import Any, Tuple
5+
from typing import Any
66

77
import cloudpickle
88
from sortedcontainers import SortedDict, SortedSet
@@ -28,7 +28,7 @@
2828
else:
2929
from typing_extensions import TypeAlias
3030

31-
PointType: TypeAlias = Tuple[Int, Any]
31+
PointType: TypeAlias = tuple[Int, Any]
3232

3333

3434
class _IgnoreFirstArgument:

adaptive/runner.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from contextlib import suppress
1616
from datetime import datetime, timedelta
1717
from importlib.util import find_spec
18-
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
18+
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union
1919

2020
import loky
2121

@@ -46,11 +46,6 @@
4646
else:
4747
from typing_extensions import TypeAlias
4848

49-
if sys.version_info >= (3, 8):
50-
from typing import Literal
51-
else:
52-
from typing_extensions import Literal
53-
5449

5550
with_ipyparallel = find_spec("ipyparallel") is not None
5651
with_distributed = find_spec("distributed") is not None

adaptive/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import os
88
import pickle
99
import warnings
10+
from collections.abc import Iterator, Sequence
1011
from contextlib import contextmanager
1112
from itertools import product
12-
from typing import Any, Callable, Iterator, Sequence
13+
from typing import Any, Callable
1314

1415
import cloudpickle
1516

@@ -147,7 +148,7 @@ class SequentialExecutor(concurrent.Executor):
147148
This executor is mainly for testing.
148149
"""
149150

150-
def submit(self, fn: Callable, *args, **kwargs) -> concurrent.Future:
151+
def submit(self, fn: Callable, *args, **kwargs) -> concurrent.Future: # type: ignore[override]
151152
fut: concurrent.Future = concurrent.Future()
152153
try:
153154
fut.set_result(fn(*args, **kwargs))

benchmarks/asv.conf.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"environment_type": "conda",
88
"install_timeout": 600,
99
"show_commit_url": "https://github.com/python-adaptive/adaptive/commits/",
10-
"pythons": ["3.7"],
10+
"pythons": ["3.11"],
1111
"conda_channels": ["conda-forge"],
1212
"matrix": {
1313
"numpy": ["1.13"],

noxfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import nox
22

33

4-
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11"])
4+
@nox.session(python=["3.9", "3.10", "3.11"])
55
@nox.parametrize("all_deps", [True, False])
66
def pytest(session, all_deps):
77
session.install(".[testing,other]" if all_deps else ".[testing]")

pyproject.toml

+4-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ dynamic = ["version"]
88
description = "Parallel active learning of mathematical functions"
99
maintainers = [{ name = "Adaptive authors" }]
1010
license = { text = "BSD" }
11-
requires-python = ">=3.7"
11+
requires-python = ">=3.9"
1212
classifiers = [
1313
"Development Status :: 4 - Beta",
1414
"License :: OSI Approved :: BSD License",
1515
"Intended Audience :: Science/Research",
16-
"Programming Language :: Python :: 3.7",
17-
"Programming Language :: Python :: 3.8",
1816
"Programming Language :: Python :: 3.9",
1917
"Programming Language :: Python :: 3.10",
2018
"Programming Language :: Python :: 3.11",
@@ -30,8 +28,6 @@ dependencies = [
3028

3129
[project.optional-dependencies]
3230
other = [
33-
"ipython; python_version > '3.8'",
34-
"ipython<8.13; python_version <= '3.8'", # because https://github.com/ipython/ipython/issues/14053
3531
"dill",
3632
"distributed",
3733
"ipyparallel>=6.2.5", # because of https://github.com/ipython/ipyparallel/issues/404
@@ -41,8 +37,7 @@ other = [
4137
"pexpect; os_name != 'nt'",
4238
]
4339
notebook = [
44-
"ipython; python_version > '3.8'",
45-
"ipython<8.13; python_version <= '3.8'", # because https://github.com/ipython/ipython/issues/14053
40+
"ipython",
4641
"ipykernel>=4.8.0", # because https://github.com/ipython/ipykernel/issues/274 and https://github.com/ipython/ipykernel/issues/263
4742
"jupyter_client>=5.2.2", # because https://github.com/jupyter/jupyter_client/pull/314
4843
"holoviews>=1.9.1",
@@ -96,11 +91,11 @@ output = ".coverage.xml"
9691

9792
[tool.mypy]
9893
ignore_missing_imports = true
99-
python_version = "3.7"
94+
python_version = "3.9"
10095

10196
[tool.ruff]
10297
line-length = 150
103-
target-version = "py37"
98+
target-version = "py39"
10499
select = ["B", "C", "E", "F", "W", "T", "B9", "I", "UP"]
105100
ignore = [
106101
"T20", # flake8-print

0 commit comments

Comments
 (0)