MCPcopy Create free account
hub / github.com/nodejs/node / Copy

Method Copy

tools/gyp/pylib/gyp/xcodeproj_file.py:305–357  ·  view source on GitHub ↗

Make a copy of this object. The new object will have its own copy of lists and dicts. Any XCObject objects owned by this object (marked "strong") will be copied in the new object, even those found in lists. If this object has any weak references to other XCObjects,

(self)

Source from the content-addressed store, hash-verified

303 return f"<{self.__class__.__name__} {name!r} at 0x{id(self):x}>"
304
305 def Copy(self):
306 """Make a copy of this object.
307
308 The new object will have its own copy of lists and dicts. Any XCObject
309 objects owned by this object (marked "strong") will be copied in the
310 new object, even those found in lists. If this object has any weak
311 references to other XCObjects, the same references are added to the new
312 object without making a copy.
313 """
314
315 that = self.__class__(id=self.id, parent=self.parent)
316 for key, value in self._properties.items():
317 is_strong = self._schema[key][2]
318
319 if isinstance(value, XCObject):
320 if is_strong:
321 new_value = value.Copy()
322 new_value.parent = that
323 that._properties[key] = new_value
324 else:
325 that._properties[key] = value
326 elif isinstance(value, (str, int)):
327 that._properties[key] = value
328 elif isinstance(value, list):
329 if is_strong:
330 # If is_strong is True, each element is an XCObject, so it's safe to
331 # call Copy.
332 that._properties[key] = []
333 for item in value:
334 new_item = item.Copy()
335 new_item.parent = that
336 that._properties[key].append(new_item)
337 else:
338 that._properties[key] = value[:]
339 elif isinstance(value, dict):
340 # dicts are never strong.
341 if is_strong:
342 raise TypeError(
343 "Strong dict for key " + key + " in " + self.__class__.__name__
344 )
345 else:
346 that._properties[key] = value.copy()
347 else:
348 raise TypeError(
349 "Unexpected type "
350 + value.__class__.__name__
351 + " for key "
352 + key
353 + " in "
354 + self.__class__.__name__
355 )
356
357 return that
358
359 def Name(self):
360 """Return the name corresponding to an object.

Callers 1

UpdatePropertiesMethod · 0.80

Calls 3

copyMethod · 0.65
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected