Generate a toggler for a boolean attribute. This returns a callable that takes no arguments.
(self, attr)
| 260 | return setter |
| 261 | |
| 262 | def toggler(self, attr): |
| 263 | """ |
| 264 | Generate a toggler for a boolean attribute. This returns a callable |
| 265 | that takes no arguments. |
| 266 | """ |
| 267 | if attr not in self._options: |
| 268 | raise KeyError("No such option: %s" % attr) |
| 269 | o = self._options[attr] |
| 270 | if o.typespec is not bool: |
| 271 | raise ValueError("Toggler can only be used with boolean options") |
| 272 | |
| 273 | def toggle(): |
| 274 | setattr(self, attr, not getattr(self, attr)) |
| 275 | |
| 276 | return toggle |
| 277 | |
| 278 | def default(self, option: str) -> Any: |
| 279 | return self._options[option].default |
no outgoing calls