From 50eab9284471a4ad45ddfdc2c15077fe7f47efe7 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Fri, 23 Jul 2021 00:55:23 +0100 Subject: [PATCH] Fix getattr uses with invalid default values (#88) --- CHANGES.md | 3 +++ threadpoolctl.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 161231f3..fab8f653 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,9 @@ 2.3.0 (in development) ====================== +- Fixed an attribute error when using old versions of OpenBLAS or BLIS that are + missing version query functions. + https://github.com/joblib/threadpoolctl/pull/88 2.2.0 (2021-07-09) diff --git a/threadpoolctl.py b/threadpoolctl.py index cc850370..94db2989 100644 --- a/threadpoolctl.py +++ b/threadpoolctl.py @@ -640,8 +640,10 @@ class _OpenBLASModule(_Module): def get_version(self): # None means OpenBLAS is not loaded or version < 0.3.4, since OpenBLAS # did not expose its version before that. - get_config = getattr(self._dynlib, "openblas_get_config", - lambda: None) + get_config = getattr(self._dynlib, "openblas_get_config", None) + if get_config is None: + return None + get_config.restype = ctypes.c_char_p config = get_config().split() if config[0] == b"OpenBLAS": @@ -683,8 +685,10 @@ def get_architecture(self): class _BLISModule(_Module): """Module class for BLIS""" def get_version(self): - get_version_ = getattr(self._dynlib, "bli_info_get_version_str", - lambda: None) + get_version_ = getattr(self._dynlib, "bli_info_get_version_str", None) + if get_version_ is None: + return None + get_version_.restype = ctypes.c_char_p return get_version_().decode("utf-8")