Do not use mutables as default values!
This blog article explains why (just an example, many other articles discuss this ad nauseam): http://pythonconquerstheuniverse.wordpress.com/2012/02/15/mutable-default-arguments/
This commit is contained in:
@@ -241,7 +241,9 @@ class Blockchain(threading.Thread):
|
||||
return h
|
||||
|
||||
|
||||
def get_target(self, index, chain=[]):
|
||||
def get_target(self, index, chain=None):
|
||||
if chain is None:
|
||||
chain = [] # Do not use mutables as default values!
|
||||
|
||||
max_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
||||
if index == 0: return 0x1d00ffff, max_target
|
||||
|
||||
@@ -34,7 +34,9 @@ class NetworkProxy(threading.Thread):
|
||||
# connects to daemon
|
||||
# sends requests, runs callbacks
|
||||
|
||||
def __init__(self, config = {}):
|
||||
def __init__(self, config=None):
|
||||
if config is None:
|
||||
config = {} # Do not use mutables as default arguments!
|
||||
threading.Thread.__init__(self)
|
||||
self.daemon = True
|
||||
self.config = SimpleConfig(config) if type(config) == type({}) else config
|
||||
|
||||
@@ -72,7 +72,9 @@ from simple_config import SimpleConfig
|
||||
|
||||
class Network(threading.Thread):
|
||||
|
||||
def __init__(self, config = {}):
|
||||
def __init__(self, config=None):
|
||||
if config is None:
|
||||
config = {} # Do not use mutables as default values!
|
||||
threading.Thread.__init__(self)
|
||||
self.daemon = True
|
||||
self.config = SimpleConfig(config) if type(config) == type({}) else config
|
||||
|
||||
Reference in New Issue
Block a user