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)
| 58 | return "{}({})".format(self.__class__.__name__, ', '.join(args)) |
| 59 | |
| 60 | def clone(self, **kw): |
| 61 | """Return a new instance with specified attributes changed. |
| 62 | |
| 63 | The new instance has the same attribute values as the current object, |
| 64 | except for the changes passed in as keyword arguments. |
| 65 | |
| 66 | """ |
| 67 | newpolicy = self.__class__.__new__(self.__class__) |
| 68 | for attr, value in self.__dict__.items(): |
| 69 | object.__setattr__(newpolicy, attr, value) |
| 70 | for attr, value in kw.items(): |
| 71 | if not hasattr(self, attr): |
| 72 | raise TypeError( |
| 73 | "{!r} is an invalid keyword argument for {}".format( |
| 74 | attr, self.__class__.__name__)) |
| 75 | object.__setattr__(newpolicy, attr, value) |
| 76 | return newpolicy |
| 77 | |
| 78 | def __setattr__(self, name, value): |
| 79 | if hasattr(self, name): |
no test coverage detected