Last active
December 19, 2015 10:39
-
-
Save flaneur2020/5942424 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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