From 38aa9db8108ef1eca5bb34488fd197ecf84e85cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Sat, 14 Sep 2024 10:03:05 +0200 Subject: [PATCH] tentative fix typechecking --- yt/_maintenance/numpy2_compat.py | 13 +++++-------- yt/_typing.py | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/yt/_maintenance/numpy2_compat.py b/yt/_maintenance/numpy2_compat.py index 3cc1f01aa1d..e9738dab10b 100644 --- a/yt/_maintenance/numpy2_compat.py +++ b/yt/_maintenance/numpy2_compat.py @@ -1,12 +1,9 @@ # avoid deprecation warnings in numpy >= 2.0 -from importlib.metadata import version +import numpy as np -from packaging.version import Version - -NUMPY_VERSION = Version(version("numpy")) - -if NUMPY_VERSION >= Version("2.0.0dev0"): - from numpy import trapezoid as trapezoid # type: ignore [attr-defined] +if hasattr(np, "trapezoid"): + # np.trapz is deprecated in numpy 2.0 in favor of np.trapezoid + trapezoid = np.trapezoid else: - from numpy import trapz as trapezoid # type: ignore [attr-defined] # noqa: F401 + trapezoid = np.trapz # noqa: NPY201 diff --git a/yt/_typing.py b/yt/_typing.py index 0aeff6d79fa..642717632bc 100644 --- a/yt/_typing.py +++ b/yt/_typing.py @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, Optional, TypeAlias import numpy as np import unyt as un @@ -25,7 +25,7 @@ AxisOrder = tuple[AxisName, AxisName, AxisName] # types that can be converted to un.Unit -Unit = un.Unit | str +Unit: TypeAlias = un.Unit | str # types that can be converted to un.unyt_quantity Quantity = un.unyt_quantity | tuple[float, Unit]