Using help (`?`) with `default_box=True` unintentionally adds a key
nishikantparmariam opened this issue · 3 comments
nishikantparmariam commented
Box is really useful when accessing non-existing keys/attributes and assigning new keys on them e.g. box.foo.bar.baz = 1
.
Noting down here an issue I have found. When IPython's help using ?
is called it adds a key getdoc
in Box object.
Version
python-box v6.1.0
Reproducer
Cause
This seems expected and is a side-effect of this line in IPython which tries a find a custom method getdoc()
to get docstring for an object.
Is there a workaround here?
nishikantparmariam commented
Ok, I've found a workaround for now -
from box import Box
class MyBox(Box):
_protected_keys = dir(Box) + ['getdoc']
def getdoc(self):
return Box.__doc__
cdgriffith commented
Hopefully fixing both getdoc
and shape
if we detect we are in an ipython console
Adding this feature in Box 7! Please test and give feedback if possible pip install python-box[all]~=7.0.0rc0
cdgriffith commented
Added in 7.0.0