Created
September 1, 2016 15:56
-
-
Save judy2k/634c5e3af1c9498f680178352b5f26eb to your computer and use it in GitHub Desktop.
Demonstrates that data descriptors have precedence over the instance dict.
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
class NonDataDescriptor(object): | |
def __get__(self, *args, **kwargs): | |
return 'magic' | |
class DataDescriptor(object): | |
def __get__(self, *args, **kwargs): | |
return 'magic' | |
def __set__(self, *args, **kwargs): | |
pass | |
class MyObject(object): | |
ndd = NonDataDescriptor() | |
dd = DataDescriptor() | |
def __init__(self): | |
self.ndd = "non-data" | |
self.dd = "data" | |
ob = MyObject() | |
print(ob.ndd) | |
print(ob.dd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: