Skip to content

Commit d329376

Browse files
added a fall back to repr, and tests
1 parent ddff001 commit d329376

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/nemos/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def format_repr(
534534
)
535535
if repr_param:
536536
if k in use_name_keys:
537-
v = v.__name__
537+
v = getattr(v, "__name__", repr(v))
538538
elif isinstance(v, str):
539539
v = repr(v)
540540
disp_params.append(f"{k}={v}")

tests/test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import warnings
22
from contextlib import nullcontext as does_not_raise
3+
from copy import deepcopy
34

45
import jax
56
import jax.numpy as jnp
@@ -595,6 +596,8 @@ def __repr__(self):
595596
(Example(a=0, b=False, c=None), None, [], "Example(a=0, b=False, d=1)"),
596597
# Falsey values excluded2
597598
(Example(a=0, b=[], c={}), None, [], "Example(a=0, d=1)"),
599+
# function without the __name__
600+
(nmo.observation_models.PoissonObservations(deepcopy(jax.numpy.exp)),None, [], "PoissonObservations(inverse_link_function=<PjitFunction>)")
598601
],
599602
)
600603
def test_format_repr(obj, exclude_keys, use_name_keys, expected):

0 commit comments

Comments
 (0)