File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed
Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -186,20 +186,24 @@ def test_union(self):
186186 with self .assertRaises (TypeError ):
187187 i |= None
188188
189- def test_factory_conflict_with_setted_value (self ):
190- test_dict = None
191- count = 0
189+ def test_factory_conflict_with_set_value (self ):
192190 key = "conflict_test"
193- def default_factory ():
194- nonlocal count
195- nonlocal test_dict
196- nonlocal key
197- count += 1
198- if count == 1 :
199- test_dict [key ] = "setted_value"
200- return "default_factory_value"
201- test_dict = defaultdict (default_factory )
202- self .assertEqual (test_dict [key ], "setted_value" )
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
205+
206+ self .assertEqual (test_dict [key ], "set_value" )
203207
204208if __name__ == "__main__" :
205209 unittest .main ()
You can’t perform that action at this time.
0 commit comments