Last active
April 15, 2016 12:41
-
-
Save Kniyl/58d145e3ec97b245b27db94d80074e81 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
class A1(object): | |
def __init__(self, **kwargs): | |
for k,v in kwargs.items(): | |
setattr(self, k, v) | |
class A2(object): | |
def __init__(self, **kwargs): | |
self.__dict__.update(kwargs) | |
class B1(A1): | |
def __init__(self): | |
super(B1, self).__init__(test=1) | |
@property | |
def test(self): | |
return 42 | |
class B2(A2): | |
def __init__(self): | |
super(B2, self).__init__(test=1) | |
@property | |
def test(self): | |
return 42 | |
test = B2() | |
print test.test # outputs 42 | |
test = B1() # AttributeError: can't set attribute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment