Skip to content

Commit 462c531

Browse files
authored
Bump mypy and ruff in pre-commit (#479)
1 parent 240fb89 commit 462c531

11 files changed

+24
-34
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v5.0.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
@@ -9,21 +9,21 @@ repos:
99
- id: debug-statements
1010
- id: check-ast
1111
- repo: https://github.com/astral-sh/ruff-pre-commit
12-
rev: "v0.3.5"
12+
rev: "v0.11.9"
1313
hooks:
1414
- id: ruff
1515
args: ["--fix"]
1616
- id: ruff-format
1717
- repo: https://github.com/nbQA-dev/nbQA
18-
rev: 1.8.5
18+
rev: 1.9.1
1919
hooks:
2020
- id: nbqa-black
2121
additional_dependencies: [jupytext, black]
2222
- id: nbqa
2323
args: ["ruff", "--fix", "--ignore=E402,B018,F704"]
2424
additional_dependencies: [jupytext, ruff]
2525
- repo: https://github.com/pre-commit/mirrors-mypy
26-
rev: "v1.9.0"
26+
rev: "v1.15.0"
2727
hooks:
2828
- id: mypy
2929
exclude: ipynb_filter.py|docs/source/conf.py

adaptive/learner/average_learner1D.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,7 @@ def tell_many( # type: ignore[override]
499499
# but ignore it going forward.
500500
if not np.prod([x >= self.bounds[0] and x <= self.bounds[1] for _, x in xs]):
501501
raise ValueError(
502-
"x value out of bounds, "
503-
"remove x or enlarge the bounds of the learner"
502+
"x value out of bounds, remove x or enlarge the bounds of the learner"
504503
)
505504

506505
# Create a mapping of points to a list of samples
@@ -533,8 +532,7 @@ def tell_many_at_point(self, x: Real, seed_y_mapping: dict[int, Real]) -> None:
533532
# Check x is within the bounds
534533
if not np.prod(x >= self.bounds[0] and x <= self.bounds[1]):
535534
raise ValueError(
536-
"x value out of bounds, "
537-
"remove x or enlarge the bounds of the learner"
535+
"x value out of bounds, remove x or enlarge the bounds of the learner"
538536
)
539537

540538
# If x is a new point:

adaptive/learner/balancing_learner.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ def __init__(
106106
self._cdims_default = cdims
107107

108108
if len({learner.__class__ for learner in self.learners}) > 1:
109-
raise TypeError(
110-
"A BalacingLearner can handle only one type" " of learners."
111-
)
109+
raise TypeError("A BalacingLearner can handle only one type of learners.")
112110

113111
self.strategy: STRATEGY_TYPE = strategy
114112

adaptive/learner/data_saver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _set_data(
162162
self.learner._set_data(learner_data)
163163

164164
def __getstate__(self) -> tuple[LearnerType, Callable, OrderedDict]:
165-
return (
165+
return ( # type: ignore[return-value]
166166
self.learner,
167167
self.arg_picker,
168168
self.extra_data,

adaptive/learner/learner1D.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,9 @@ def _ask_points_without_adding(self, n: int) -> tuple[list[float], list[float]]:
761761
ival is not None
762762
and self._loss(self.losses_combined, ival) >= self._loss(quals, qual)
763763
):
764+
assert ival is not None
764765
i += 1
765-
quals[(*ival, 2)] = loss_ival / 2
766+
quals[(ival[0], ival[1], 2)] = loss_ival / 2
766767
else:
767768
quals.pop(qual, None)
768769
*xs, n = qual

adaptive/learner/learner2D.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def __init__(
448448
self.aspect_ratio = 1
449449

450450
self._bounds_points = list(itertools.product(*bounds))
451-
self._stack.update({p: np.inf for p in self._bounds_points})
451+
self._stack.update(dict.fromkeys(self._bounds_points, np.inf))
452452
self.function = function # type: ignore
453453
self._ip = self._ip_combined = None
454454

adaptive/learner/learnerND.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,7 @@ def _get_iso(self, level=0.0, which="surface"):
10981098
if which == "surface":
10991099
if self.ndim != 3 or self.vdim != 1:
11001100
raise Exception(
1101-
"Isosurface plotting is only supported"
1102-
" for a 3D input and 1D output"
1101+
"Isosurface plotting is only supported for a 3D input and 1D output"
11031102
)
11041103
get_surface = True
11051104
get_line = False

adaptive/learner/triangulation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ def __init__(self, coords):
336336
vectors = subtract(coords[1:], coords[0])
337337
if matrix_rank(vectors) < dim:
338338
raise ValueError(
339-
"Initial simplex has zero volumes "
340-
"(the points are linearly dependent)"
339+
"Initial simplex has zero volumes (the points are linearly dependent)"
341340
)
342341

343342
self.vertices = list(coords)

adaptive/notebook_integration.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def notebook_extension(*, _inline_js=True):
1616
"""Enable ipywidgets, holoviews, and asyncio notebook integration."""
1717
if not in_ipynb():
1818
raise RuntimeError(
19-
'"adaptive.notebook_extension()" may only be run '
20-
"from a Jupyter notebook."
19+
'"adaptive.notebook_extension()" may only be run from a Jupyter notebook.'
2120
)
2221

2322
global _holoviews_enabled, _ipywidgets_enabled
@@ -116,8 +115,7 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None, normalize=T
116115
"""
117116
if not _holoviews_enabled:
118117
raise RuntimeError(
119-
"Live plotting is not enabled; did you run "
120-
"'adaptive.notebook_extension()'?"
118+
"Live plotting is not enabled; did you run 'adaptive.notebook_extension()'?"
121119
)
122120

123121
import holoviews as hv
@@ -202,8 +200,7 @@ def live_info(runner, *, update_interval=0.5):
202200
"""
203201
if not _holoviews_enabled:
204202
raise RuntimeError(
205-
"Live plotting is not enabled; did you run "
206-
"'adaptive.notebook_extension()'?"
203+
"Live plotting is not enabled; did you run 'adaptive.notebook_extension()'?"
207204
)
208205

209206
import ipywidgets
@@ -268,7 +265,7 @@ def _info_html(runner):
268265
info.append(("# of samples", runner.learner.nsamples))
269266

270267
with suppress(Exception):
271-
info.append(("latest loss", f'{runner.learner._cache["loss"]:.3f}'))
268+
info.append(("latest loss", f"{runner.learner._cache['loss']:.3f}"))
272269

273270
table = "\n".join(_table_row(i, k, v) for i, (k, v) in enumerate(info))
274271

adaptive/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ def auto_goal(
11571157
if isinstance(learner, DataSaver):
11581158
assert learner is not None
11591159
return auto_goal(
1160-
learner=learner.learner,
1160+
learner=learner.learner, # type: ignore[arg-type]
11611161
loss=loss,
11621162
npoints=npoints,
11631163
end_time=end_time,

0 commit comments

Comments
 (0)