Last active
May 27, 2017 09:26
-
-
Save AstraLuma/c1a3cdd46457cae5602b03f6ce1e4572 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
| class Top: | |
| @property | |
| def foo(self): | |
| ... | |
| @foo.setter | |
| def set_foo(self, value): | |
| ... | |
| class Spam(Top): | |
| @property | |
| def foo(self) | |
| return super().foo | |
| @foo.setter | |
| def foo(self, value): | |
| super().foo = value | |
| ... |
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
| class Top: | |
| def get_foo(self): | |
| ... | |
| def set_foo(self, value): | |
| ... | |
| foo = property(get_foo, set_foo) | |
| class Spam(Top): | |
| # Probably the simplest, but ignores MRO | |
| def set_foo(self, value): | |
| super().set_foo(value) | |
| ... | |
| foo = property(Top.get_foo, set_foo) | |
| class Eggs(Top): | |
| # More complicated, but respects MRO | |
| def set_foo(self, value): | |
| super().set_foo(value) | |
| ... | |
| foo = property( | |
| (lambda self: self.get_foo()), | |
| (lambda self, value: self.set_foo(value) | |
| ) | |
| class Sausage(Top): | |
| # This just won't work | |
| def set_foo(self, value): | |
| super().set_foo(value) | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a working example of property extension: