Created
January 4, 2015 12:59
-
-
Save kiyohara/836bb3d482b807f91cee to your computer and use it in GitHub Desktop.
default arg trap
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 X: | |
def __init__(self, x={}): | |
self.var = x | |
def set(self, val): | |
self.var['key'] = val | |
class Y(X): | |
def __init__(self,x=None): | |
self.var = x if x is not None else {} | |
if __name__ == '__main__': | |
x1 = X() | |
x1.set('test') | |
print x1.var # {'key': 'test'} | |
x2 = X() | |
print x2.var # {'key': 'test'} | |
y1 = Y() | |
y1.set('test') | |
print y1.var # {'key': 'test'} | |
y2 = Y() | |
print y2.var # {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment