-
-
Save naufraghi/6070273 to your computer and use it in GitHub Desktop.
This file contains 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
# This is the "normal" way | |
class C(object): | |
def __init__(self): | |
self._x = None | |
@property | |
def x(self): | |
return self._x | |
@x.setter # will copy C.x and add the setter | |
def x(self, value): | |
self._x = value | |
@x.deleter # will copy the new C.x and add the deleter | |
def x(self): | |
del self._x | |
# This is an history preserving way | |
class C(object): | |
def __init__(self): | |
self._x = None | |
@property | |
def get_x(self): | |
return self._x | |
@get_x.setter # will copy C.get_x and add the setter | |
def set_x(self, value): | |
self._x = value | |
@set_x.deleter # will copy C.set_x and add the deleter | |
def x(self): # The last name is the one we will use | |
del self._x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, long story short, what really happens in the code is that every @x.[setter|setter|deleter] makes a copy of the referred property and plugs it in the new name.
https://gist.github.com/naufraghi/6070273
http://svn.python.org/view/python/trunk/Objects/descrobject.c?view=markup#l1211
What I miss is why a copy is done instead of modifying the first defined property.