MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / copy

Function copy

tools/python-3.11.9-amd64/Lib/copy.py:66–102  ·  view source on GitHub ↗

Shallow copy operation on arbitrary Python objects. See the module's __doc__ string for more info.

(x)

Source from the content-addressed store, hash-verified

64__all__ = ["Error", "copy", "deepcopy"]
65
66def copy(x):
67 """Shallow copy operation on arbitrary Python objects.
68
69 See the module's __doc__ string for more info.
70 """
71
72 cls = type(x)
73
74 copier = _copy_dispatch.get(cls)
75 if copier:
76 return copier(x)
77
78 if issubclass(cls, type):
79 # treat it as a regular class:
80 return _copy_immutable(x)
81
82 copier = getattr(cls, "__copy__", None)
83 if copier is not None:
84 return copier(x)
85
86 reductor = dispatch_table.get(cls)
87 if reductor is not None:
88 rv = reductor(x)
89 else:
90 reductor = getattr(x, "__reduce_ex__", None)
91 if reductor is not None:
92 rv = reductor(4)
93 else:
94 reductor = getattr(x, "__reduce__", None)
95 if reductor:
96 rv = reductor()
97 else:
98 raise Error("un(shallow)copyable object of type %s" % cls)
99
100 if isinstance(rv, str):
101 return x
102 return _reconstruct(x, None, *rv)
103
104
105_copy_dispatch = d = {}

Callers 1

setUpMethod · 0.90

Calls 5

_copy_immutableFunction · 0.85
_reconstructFunction · 0.85
ErrorClass · 0.70
typeClass · 0.50
getMethod · 0.45

Tested by 1

setUpMethod · 0.72