##// END OF EJS Templates
don't deep-copy instances when copying config...
Min RK -
Show More
@@ -233,13 +233,26 b' class Config(dict):'
233 233
234 234 def copy(self):
235 235 return type(self)(dict.copy(self))
236 # copy nested config objects
237 for k, v in self.items():
238 if isinstance(v, Config):
239 new_config[k] = v.copy()
240 return new_config
236 241
237 242 def __copy__(self):
238 243 return self.copy()
239 244
240 245 def __deepcopy__(self, memo):
241 import copy
242 return type(self)(copy.deepcopy(list(self.items())))
246 new_config = type(self)()
247 for key, value in self.items():
248 if isinstance(value, (Config, LazyConfigValue)):
249 # deep copy config objects
250 value = copy.deepcopy(value, memo)
251 elif type(value) in {dict, list, set, tuple}:
252 # shallow copy plain container traits
253 value = copy.copy(value)
254 new_config[key] = value
255 return new_config
243 256
244 257 def __getitem__(self, key):
245 258 try:
@@ -4,6 +4,8 b''
4 4 # Copyright (c) IPython Development Team.
5 5 # Distributed under the terms of the Modified BSD License.
6 6
7 import copy
8 import logging
7 9 import os
8 10 import pickle
9 11 import sys
@@ -319,11 +321,15 b' class TestConfig(TestCase):'
319 321 c1.Foo.bam = 30
320 322 c1.a = 'asdf'
321 323 c1.b = range(10)
322 import copy
324 c1.Test.logger = logging.Logger('test')
325 c1.Test.get_logger = logging.getLogger('test')
323 326 c2 = copy.deepcopy(c1)
324 327 self.assertEqual(c1, c2)
325 328 self.assertTrue(c1 is not c2)
326 329 self.assertTrue(c1.Foo is not c2.Foo)
330 self.assertTrue(c1.Test is not c2.Test)
331 self.assertTrue(c1.Test.logger is c2.Test.logger)
332 self.assertTrue(c1.Test.get_logger is c2.Test.get_logger)
327 333
328 334 def test_builtin(self):
329 335 c1 = Config()
General Comments 0
You need to be logged in to leave comments. Login now