From c057ae58ff7e4add7d437f2159364880adc5c39d Mon Sep 17 00:00:00 2001 From: adigitoleo Date: Tue, 13 Aug 2024 15:23:01 +1000 Subject: [PATCH] fix: Fix serializability check for DefaultParams Checking `isinstance(foo, Hashable)` is not sufficient, that only checks for the *existance* of a `__hash__` method, not whether it can actually evaluate without raising. --- src/pydrex/core.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pydrex/core.py b/src/pydrex/core.py index 011596c4..9c8831b0 100644 --- a/src/pydrex/core.py +++ b/src/pydrex/core.py @@ -129,10 +129,11 @@ class DefaultParams: Use `as_dict` to get a mutable copy. >>> defaults = DefaultParams() - >>> from collections.abc import Hashable - >>> isinstance(defaults, Hashable) # supports hash() + >>> # Evaluating hash() will raise an error if the argument is mutable. + >>> isinstance(hash(defaults), int) True - >>> isinstance(defaults.as_dict(), Hashable) + >>> from collections.abc import Hashable + >>> isinstance(defaults.as_dict(), Hashable) # No longer supports hash(). False """