From 4f4ef9301f76ea802fabe66aad10ec6e4710c3bd Mon Sep 17 00:00:00 2001 From: rettigl Date: Sat, 14 Oct 2023 23:37:13 +0200 Subject: [PATCH] add hacks to satisfy mypy due to apparent bugs in typing --- sed/calibrator/energy.py | 4 +++- tests/test_binning.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sed/calibrator/energy.py b/sed/calibrator/energy.py index 8a01fab9..ec19f72e 100644 --- a/sed/calibrator/energy.py +++ b/sed/calibrator/energy.py @@ -1732,8 +1732,10 @@ def peakdetect1d( if lookahead < 1: raise ValueError("Lookahead must be '1' or above in value") - if not (np.isscalar(delta) and delta >= 0): + if not (np.isscalar(delta) and cast(int, delta) >= 0): raise ValueError("delta must be a positive number") + # Hack because TypeGuard with numpy 1.22.4 seems broken + delta = cast(int, delta) # maxima and minima candidates are temporarily stored in # mx and mn respectively diff --git a/tests/test_binning.py b/tests/test_binning.py index 871be1bc..fceceb78 100644 --- a/tests/test_binning.py +++ b/tests/test_binning.py @@ -1,6 +1,7 @@ """This file contains code that performs several tests for the sed.binning module """ from typing import Any +from typing import cast from typing import List from typing import Sequence from typing import Tuple @@ -394,7 +395,8 @@ def test_simplify_binning_arguments( ) for i, bin_ in enumerate(bins__): - np.testing.assert_array_equal(bin_, bins_expected[i]) + # TODO: Why does typing fail? + np.testing.assert_array_equal(cast(np.ndarray, bin_), bins_expected[i]) np.testing.assert_array_equal(axes__[i], axes_expected[i]) if ranges__ is not None: np.testing.assert_array_equal(ranges__[i], ranges_expected[i])