Skip to content

Instantly share code, notes, and snippets.

@flaneur2020
Last active December 19, 2015 10:39
Show Gist options
  • Select an option

  • Save flaneur2020/5942424 to your computer and use it in GitHub Desktop.

Select an option

Save flaneur2020/5942424 to your computer and use it in GitHub Desktop.
def _forward_attr_to_dict(cls, target, field):
_property = property( \
lambda obj: getattr(obj, target)[field],
lambda obj, value: getattr(obj, target).__setitem__(field, value))
setattr(cls, field, _property)
def _forward_attrs_to_dict(cls, target, fields=[]):
for field in fields:
_forward_attr_to_dict(cls, target, field)
return cls
def forward_attrs_to_dict(target, fields):
return lambda cls: _forward_attrs_to_dict(cls, target, fields)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment