-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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:
value = a.key.pathinstead of
value = a['key']['path']
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.applesetattr(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
Metadata
Metadata
Assignees
Labels
No labels
