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

Keys starting with __ can't be referenced with dotted notation inside an object #149

Open
ramonfm opened this issue Sep 24, 2022 · 0 comments

Comments

@ramonfm
Copy link

ramonfm commented Sep 24, 2022

See below; keys that start with __ can't be referenced inside an object with dotted notation. If I define missing() I get "KeyError: '_Stuff__metadata'".

Thanks for this awesome piece of software BTW -- makes my life much better.

import addict
from pprint import pformat


data = {
    'foo': 7,
    'bar': {
        'metadata': {'text': 'this works', 'value': True},
        '__metadata': {'text': 'this works', 'value': False}
    }
}
dotted = addict.Dict(data)


class Stuff(object):
    def __init__(self):
        pass

    def run(self):
        assert pformat(data['bar']) == pformat(dotted.bar), 'text representation does not work'
        assert dotted.bar.metadata.text == dotted.bar['__metadata'].text, 'mixed reference broken inside an object'
        assert dotted.bar.metadata.text == dotted.bar.__metadata.text, 'dotted reference broken inside an object'


assert dotted.bar.metadata.text == dotted.bar.__metadata.text, 'broken outside an object'
Stuff().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant