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)
| 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): |
no test coverage detected