File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed
Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -188,20 +188,18 @@ def test_union(self):
188188
189189 def test_factory_conflict_with_set_value (self ):
190190 key = "conflict_test"
191- class Factory :
192- def __init__ (self ):
193- self .count = 0
194- self .test_dict = None
195-
196- def __call__ (self ):
197- self .count += 1
198- if self .count == 1 :
199- self .test_dict [key ] = "set_value"
200- return "default_factory_value"
201-
202- factory = Factory ()
203- test_dict = defaultdict (factory )
204- factory .test_dict = test_dict
191+ count = 0
192+ test_dict = None
193+
194+ def default_factory ():
195+ nonlocal count
196+ nonlocal test_dict
197+ count += 1
198+ if count == 1 :
199+ test_dict [key ] = "set_value"
200+ return "default_factory_value"
201+
202+ test_dict = defaultdict (default_factory )
205203
206204 self .assertEqual (test_dict [key ], "set_value" )
207205
You can’t perform that action at this time.
0 commit comments