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

Dict Attributes not available to Autocomplete and not present in __dict__ #143

Open
LarsHill opened this issue Sep 14, 2021 · 4 comments
Open

Comments

@LarsHill
Copy link

Hi,
When I convert a normal dictionary like

some_dict = {'a': 1, 'b': 2, 'c': 3}

to an attribute dictionary via

from addict import Dict
attribute_dict = Dict(some_dict)

I would expect being able to hit tab in order to access an attribute via autocomplete (as usual with classes). However, all the keys from some_dict are not present. Also attribute_dict.__dict__ only returns the following:
{'__parent': None, '__key': None, '__frozen': False}.

Is that intended, or am I missing something on my side?

As a side note, I installed addict version 2.4.0 via pip.

@zyLiu6707
Copy link

Same here: it would be great and convenient if addict can support autocompletion in common IDEs.

@LarsHill
Copy link
Author

@zyLiu6707 In the meantime I developed my own solution since I was not sattisfied with addict and other comparable projects.
It's called MetaDict and behaves exactly like a dict with the addition of enabling (nested) attribute-style key access/assignment and IDE autocompletion.

It might suit your usecase :)

@zyLiu6707
Copy link

Thank you Lars, I'll check it out :)

@jj-github-jj
Copy link

I modified by adding this to the addict.py and autocomplete start working . Thanks to https://stackoverflow.com/questions/51917470/what-does-tab-completion-in-ipython-or-jupyter-seek-in-order-to-suggest-alternat
can you make this change? not versed enough in github pull requests etc else I would have done it
def dir(self):
super_dir = super().dir()
string_keys = [key for key in self if type(key) is str]
return super_dir + [key for key in string_keys if key not in super_dir]

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

3 participants