MCPcopy Index your code
hub / github.com/python/cpython / clone

Method clone

Lib/email/_policybase.py:69–85  ·  view source on GitHub ↗

Return a new instance with specified attributes changed. The new instance has the same attribute values as the current object, except for the changes passed in as keyword arguments.

(self, **kw)

Source from the content-addressed store, hash-verified

67 return "{}({})".format(self.__class__.__name__, ', '.join(args))
68
69 def clone(self, **kw):
70 """Return a new instance with specified attributes changed.
71
72 The new instance has the same attribute values as the current object,
73 except for the changes passed in as keyword arguments.
74
75 """
76 newpolicy = self.__class__.__new__(self.__class__)
77 for attr, value in self.__dict__.items():
78 object.__setattr__(newpolicy, attr, value)
79 for attr, value in kw.items():
80 if not hasattr(self, attr):
81 raise TypeError(
82 "{!r} is an invalid keyword argument for {}".format(
83 attr, self.__class__.__name__))
84 object.__setattr__(newpolicy, attr, value)
85 return newpolicy
86
87 def __setattr__(self, name, value):
88 if hasattr(self, name):

Callers 1

__add__Method · 0.95

Calls 4

__new__Method · 0.45
itemsMethod · 0.45
__setattr__Method · 0.45
formatMethod · 0.45

Tested by

no test coverage detected