Skip to content

Commit 42a039d

Browse files
pranasziaukascmccandless
authored andcommitted
dot-dsl: remove mutable default arguments (exercism#1838)
1 parent f86042e commit 42a039d

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

exercises/dot-dsl/dot_dsl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Node(object):
5-
def __init__(self, name, attrs={}):
5+
def __init__(self, name, attrs):
66
self.name = name
77
self.attrs = attrs
88

@@ -11,7 +11,7 @@ def __eq__(self, other):
1111

1212

1313
class Edge(object):
14-
def __init__(self, src, dst, attrs={}):
14+
def __init__(self, src, dst, attrs):
1515
self.src = src
1616
self.dst = dst
1717
self.attrs = attrs
@@ -23,5 +23,5 @@ def __eq__(self, other):
2323

2424

2525
class Graph(object):
26-
def __init__(self, data=[]):
26+
def __init__(self, data=None):
2727
pass

exercises/dot-dsl/dot_dsl_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_graph_with_one_node(self):
1616
(NODE, "a", {})
1717
])
1818

19-
self.assertEqual(g.nodes, [Node("a")])
19+
self.assertEqual(g.nodes, [Node("a", {})])
2020
self.assertEqual(g.edges, [])
2121
self.assertEqual(g.attrs, {})
2222

exercises/dot-dsl/example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Node(object):
5-
def __init__(self, name, attrs={}):
5+
def __init__(self, name, attrs):
66
self.name = name
77
self.attrs = attrs
88

@@ -11,7 +11,7 @@ def __eq__(self, other):
1111

1212

1313
class Edge(object):
14-
def __init__(self, src, dst, attrs={}):
14+
def __init__(self, src, dst, attrs):
1515
self.src = src
1616
self.dst = dst
1717
self.attrs = attrs
@@ -23,11 +23,14 @@ def __eq__(self, other):
2323

2424

2525
class Graph(object):
26-
def __init__(self, data=[]):
26+
def __init__(self, data=None):
2727
self.nodes = []
2828
self.edges = []
2929
self.attrs = {}
3030

31+
if data is None:
32+
data = []
33+
3134
if not isinstance(data, list):
3235
raise TypeError("Graph data malformed")
3336

0 commit comments

Comments
 (0)