Skip to content

Commit cafd183

Browse files
Give UNSET its own type with a nice repr to make help() output nicer to read
1 parent b7cb362 commit cafd183

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pymc3/tests/test_util.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import pymc3 as pm
2121

2222
from pymc3.distributions.transforms import Transform
23-
from pymc3.util import hash_key, hashable, locally_cachedmethod
23+
from pymc3.util import UNSET, hash_key, hashable, locally_cachedmethod
2424

2525

2626
class TestTransformName:
@@ -127,3 +127,12 @@ def some_method(self, x):
127127

128128
tc = TestClass()
129129
assert tc.some_method(b1) != tc.some_method(b2)
130+
131+
132+
def test_unset_repr(capsys):
133+
def fn(a=UNSET):
134+
return
135+
136+
help(fn)
137+
captured = capsys.readouterr()
138+
assert "a=UNSET" in captured.out

pymc3/util.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@
2424

2525
from cachetools import LRUCache, cachedmethod
2626

27-
UNSET = object()
27+
28+
class _UnsetType:
29+
"""Type for the `UNSET` object to make it look nice in `help(...)` outputs."""
30+
31+
def __str__(self):
32+
return "UNSET"
33+
34+
def __repr__(self):
35+
return str(self)
36+
37+
38+
UNSET = _UnsetType()
2839

2940

3041
def withparent(meth):

0 commit comments

Comments
 (0)