addict icon indicating copy to clipboard operation
addict copied to clipboard

Dict Attributes not available to Autocomplete and not present in __dict__

Open LarsHill opened this issue 2 years ago • 4 comments

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.

LarsHill avatar Sep 14 '21 08:09 LarsHill

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

zyLiu6707 avatar Feb 22 '22 09:02 zyLiu6707

@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 :)

LarsHill avatar Feb 23 '22 09:02 LarsHill

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

zyLiu6707 avatar Feb 25 '22 08:02 zyLiu6707

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]

jj-github-jj avatar May 31 '22 00:05 jj-github-jj