There is a better way:
>>> print SourceDetectionTask.ConfigClass.thresholdType.__doc__
specifies the desired flavor of Threshold
Allowed values:
pixel_stdev threshold applied to per-pixel std deviation
variance threshold applied to image variance
value threshold applied to image value
stdev threshold applied to image std deviation
Obviously, that’s not at all easy to guess, and now that I think about it, it could be really hard to get this displayed more automatically. There are two problems.
The first is that config fields are descriptors, and I think that makes getting the right help from a config instance impossible using the idiomatic Python approach (it’s a Python language limitation): once we’ve said config.thresholdType
, all we have is the string value, and there’s no way for Python’s help()
function to do anything useful with that. Maybe we could have a string subclass that holds the documentation? But even if we did, we’d run into the next problem…
Getting the right help from a config class is broken by a choice made by the Python help()
function. Doing SourceDetectionTask.ConfigClass.thresholdType
returns an instance of pex.config.ChoiceField
that has the __doc__
attribute that we want - but that __doc__
is an instance attribute, not a class attribute. A class __doc__
attribute also exists (this is the documentation for pex.config.ChoiceField
itself), and that’s what help()
displays (and by extension, IPython’s ?
operator). We’re not the only ones who have this problem: compare print numpy.sin.__doc__
with help(numpy.sin)
. There might be some hook to customize what help()
does, but if there is, I’m surprised NumPy hasn’t utilized it yet.