public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 
 
class What(object):
def __init__(self, arg={}):
self.arg = arg
assert not len(self.arg)
arg[1] = 2
 
What()
# Whoops... arg is a mutable object
What()
 
"""
Traceback (most recent call last):
File "a.py", line 9, in <module>
What()
File "a.py", line 5, in __init__
assert not len(self.arg)
AssertionError
"""

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.