non-caching _generative() decorator. This is basically the legacy decorator that copies the object and runs a method on the new copy.
(fn: _Fn)
| 267 | |
| 268 | |
| 269 | def _generative(fn: _Fn) -> _Fn: |
| 270 | """non-caching _generative() decorator. |
| 271 | |
| 272 | This is basically the legacy decorator that copies the object and |
| 273 | runs a method on the new copy. |
| 274 | |
| 275 | """ |
| 276 | |
| 277 | @util.decorator |
| 278 | def _generative( |
| 279 | fn: _Fn, self: _SelfGenerativeType, *args: Any, **kw: Any |
| 280 | ) -> _SelfGenerativeType: |
| 281 | """Mark a method as generative.""" |
| 282 | |
| 283 | self = self._generate() |
| 284 | x = fn(self, *args, **kw) |
| 285 | assert x is self, "generative methods must return self" |
| 286 | return self |
| 287 | |
| 288 | decorated = _generative(fn) |
| 289 | decorated.non_generative = fn # type: ignore |
| 290 | return decorated |
| 291 | |
| 292 | |
| 293 | def _exclusive_against(*names: str, **kw: Any) -> Callable[[_Fn], _Fn]: |