Skip to content

Commit 97b1f58

Browse files
committed
Provide more informative error message
1 parent 38ef6cc commit 97b1f58

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pymc/distributions/distribution.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ def __new__(
322322
else:
323323
name = _extract_target_of_assignment(2)
324324
if name is None:
325-
raise TypeError("Name could not be inferred for variable")
325+
raise TypeError(
326+
"Name could not be inferred for variable from surrounding "
327+
"context. Pass a name explicitly as the first argument to "
328+
"the Distribution."
329+
)
326330

327331
if not isinstance(name, string_types):
328332
raise TypeError(f"Name needs to be a string but got: {name}")

pymc/tests/distributions/test_distribution.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ def test_autonaming():
433433

434434
def test_autonaming_noname():
435435
"""Test that autonaming fails if no assignment can be found"""
436-
with pytest.raises(TypeError, match="Name could not be inferred for variable"):
436+
with pytest.raises(
437+
TypeError,
438+
match=(
439+
"Name could not be inferred for variable from surrounding "
440+
"context. Pass a name explicitly as the first argument to "
441+
"the Distribution."
442+
),
443+
):
437444
with pm.Model():
438445
pm.Normal()

0 commit comments

Comments
 (0)