Skip to content

Commit 8818b71

Browse files
committed
refactor: safer fallback if user code changes str_repr
1 parent 75045b3 commit 8818b71

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

pymc3/printing.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,12 @@ def str_for_potential_or_deterministic(
9999

100100

101101
def _str_for_input_var(var: Variable, formatting: str) -> str:
102-
# note we're dispatching both on type(var) and on type(var.owner.op) so cannot
103-
# use the standard functools.singledispatch
104-
105102
def _is_potential_or_determinstic(var: Variable) -> bool:
106-
return (
107-
hasattr(var, "str_repr")
108-
and var.str_repr.__func__.func is str_for_potential_or_deterministic
109-
)
103+
try:
104+
return var.str_repr.__func__.func is str_for_potential_or_deterministic
105+
except AttributeError:
106+
# in case other code overrides str_repr, fallback
107+
return False
110108

111109
if isinstance(var, TensorConstant):
112110
return _str_for_constant(var, formatting)

0 commit comments

Comments
 (0)