cdgriffith / Box

Python dictionaries with advanced dot notation access

Home Page:https://github.com/cdgriffith/Box/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using help (`?`) with `default_box=True` unintentionally adds a key

nishikantparmariam opened this issue · comments

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

box-repro

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?

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__

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

Added in 7.0.0