Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nishikantparmariam opened this issue Dec 19, 2022 · 3 comments
Closed

Comments

@nishikantparmariam
Copy link

nishikantparmariam commented Dec 19, 2022

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?

@nishikantparmariam
Copy link
Author

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 added a commit that referenced this issue Jan 28, 2023
…key (thanks to Nishikant Parmar)

Fixing union operations from creating dicts instead of Boxes on certain python versions.

Readme and setup updates
cdgriffith added a commit that referenced this issue Jan 28, 2023
…te keys (thanks to Rexbard)

* Adding #236 iPython detection to prevent adding attribute lookup words (thanks to Nishikant Parmar)
* Adding new DDBox class (Default Dots Box) that is a subclass of SBox
@cdgriffith
Copy link
Owner

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 added a commit that referenced this issue Feb 4, 2023
* Adding #169 default functions with the box_instance and key parameter (thanks to Коптев Роман Викторович)
* Adding #170 Be able to initialize with a flattened dict - by using DDBox (thanks to Ash A.)
* Adding #192 box_dots treats all keys with periods in them as separate keys (thanks to Rexbard)
* Adding #211 support for properties and setters in subclasses (thanks to Serge Lu and David Aronchick)
* Adding #226 namespace to track changes to the box (thanks to Jacob Hayes)
* Adding #236 iPython detection to prevent adding attribute lookup words (thanks to Nishikant Parmar)
* Adding #238 allow ``|`` and ``+`` for frozen boxes (thanks to Peter B)
* Adding new DDBox class (Default Dots Box) that is a subclass of SBox
* Fixing #235 how ``|`` and ``+`` updates were performed for right operations (thanks to aviveh21)
* Fixing #234 typos (thanks to Martin Schorfmann)
* Fixing no implicit optionals with type hinting
@cdgriffith
Copy link
Owner

Added in 7.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants