non-caching _generative() decorator. This is basically the legacy decorator that copies the object and runs a method on the new copy.
(fn: _Fn)
| 279 | |
| 280 | |
| 281 | def _generative(fn: _Fn) -> _Fn: |
| 282 | """non-caching _generative() decorator. |
| 283 | |
| 284 | This is basically the legacy decorator that copies the object and |
| 285 | runs a method on the new copy. |
| 286 | |
| 287 | """ |
| 288 | |
| 289 | @util.decorator |
| 290 | def _generative( |
| 291 | fn: _Fn, self: _SelfGenerativeType, *args: Any, **kw: Any |
| 292 | ) -> _SelfGenerativeType: |
| 293 | """Mark a method as generative.""" |
| 294 | |
| 295 | self = self._generate() |
| 296 | x = fn(self, *args, **kw) |
| 297 | assert x is self, "generative methods must return self" |
| 298 | return self |
| 299 | |
| 300 | decorated = _generative(fn) |
| 301 | decorated.non_generative = fn # type: ignore |
| 302 | return decorated |
| 303 | |
| 304 | |
| 305 | def _exclusive_against(*names: str, **kw: Any) -> Callable[[_Fn], _Fn]: |