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

File tree

14 files changed

+41
-50
lines changed

14 files changed

+41
-50
lines changed

.github/workflows/nox.yml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 5 additions & 8 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 11 additions & 10 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 6 deletions
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

0 commit comments

Comments
 (0)