One of the main uses of dol.sources.AttrContainer is to be able to wrap mappings (say dicts) that allow a user to use tab-completion to access values through a path of keys. For example, being able to write this:
instead of
With dol.sources.AttrContainer, tab-completion works in browser-based jupyter, but doesn't work in PyCharm.
Is there a magic/dunder method that I can add to make it work?

If I define attributes at class definition time, tab-completion works though.
class SettingAttrWithSetattr:
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
from dol.sources import AttrContainer
def wrap_mapping_with_attr_access(**kwargs):
return type('A', (), kwargs)() # works
# mk_instance = AttrContainer # (tab-completion) doesn't work (in pycharm)
mk_instance = SettingAttrWithSetattr # (tab-completion) doesn't work (in pycharm)
# mk_instance = wrap_mapping_with_attr_access # WORKS
# mk_instance = WithHardCodedClassAttributes # WORKS
a = mk_instance(apple=1, banana=2)
t = a.apple
setattr(a, 'cherry', 3)
tt = a.cherry # tab-complete DOES NOT work
a.cherry = 3
tt = a.cherry # tab-complete works
┆Issue is synchronized with this Asana task by Unito
One of the main uses of
dol.sources.AttrContaineris to be able to wrap mappings (say dicts) that allow a user to use tab-completion to access values through a path of keys. For example, being able to write this:instead of
With
dol.sources.AttrContainer, tab-completion works in browser-based jupyter, but doesn't work in PyCharm.Is there a magic/dunder method that I can add to make it work?
If I define attributes at class definition time, tab-completion works though.
┆Issue is synchronized with this Asana task by Unito