Skip to content

Commit

Permalink
fix: Fix serializability check for DefaultParams
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adigitoleo committed Aug 13, 2024
1 parent 1f5a52f commit c057ae5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/pydrex/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down

0 comments on commit c057ae5

Please sign in to comment.