|
11 | 11 | from typing import Any
|
12 | 12 | from typing import Callable
|
13 | 13 | from typing import Final
|
| 14 | +from typing import final |
14 | 15 | from typing import Generator
|
15 | 16 | from typing import List
|
16 | 17 | from typing import Mapping
|
@@ -69,6 +70,7 @@ class HookimplOpts(TypedDict):
|
69 | 70 | specname: str | None
|
70 | 71 |
|
71 | 72 |
|
| 73 | +@final |
72 | 74 | class HookspecMarker:
|
73 | 75 | """Decorator for marking functions as hook specifications.
|
74 | 76 |
|
@@ -146,6 +148,7 @@ def setattr_hookspec_opts(func: _F) -> _F:
|
146 | 148 | return setattr_hookspec_opts
|
147 | 149 |
|
148 | 150 |
|
| 151 | +@final |
149 | 152 | class HookimplMarker:
|
150 | 153 | """Decorator for marking functions as hook implementations.
|
151 | 154 |
|
@@ -341,6 +344,7 @@ def varnames(func: object) -> tuple[tuple[str, ...], tuple[str, ...]]:
|
341 | 344 | return args, kwargs
|
342 | 345 |
|
343 | 346 |
|
| 347 | +@final |
344 | 348 | class HookRelay:
|
345 | 349 | """Hook holder object for performing 1:N hook calls where N is the number
|
346 | 350 | of registered plugins."""
|
@@ -382,10 +386,12 @@ def __init__(
|
382 | 386 | spec_opts: HookspecOpts | None = None,
|
383 | 387 | ) -> None:
|
384 | 388 | """:meta private:"""
|
| 389 | + #: Name of the hook getting called. |
385 | 390 | self.name: Final = name
|
386 | 391 | self._hookexec: Final = hook_execute
|
387 | 392 | self._hookimpls: Final[list[HookImpl]] = []
|
388 | 393 | self._call_history: _CallHistory | None = None
|
| 394 | + # TODO: Document, or make private. |
389 | 395 | self.spec: HookSpec | None = None
|
390 | 396 | if specmodule_or_class is not None:
|
391 | 397 | assert spec_opts is not None
|
@@ -606,6 +612,7 @@ def __repr__(self) -> str:
|
606 | 612 | return f"<_SubsetHookCaller {self.name!r}>"
|
607 | 613 |
|
608 | 614 |
|
| 615 | +@final |
609 | 616 | class HookImpl:
|
610 | 617 | """A hook implementation in a :class:`HookCaller`."""
|
611 | 618 |
|
@@ -635,34 +642,35 @@ def __init__(
|
635 | 642 | self.function: Final = function
|
636 | 643 | argnames, kwargnames = varnames(self.function)
|
637 | 644 | #: The positional parameter names of ``function```.
|
638 |
| - self.argnames = argnames |
| 645 | + self.argnames: Final = argnames |
639 | 646 | #: The keyword parameter names of ``function```.
|
640 |
| - self.kwargnames = kwargnames |
| 647 | + self.kwargnames: Final = kwargnames |
641 | 648 | #: The plugin which defined this hook implementation.
|
642 |
| - self.plugin = plugin |
| 649 | + self.plugin: Final = plugin |
643 | 650 | #: The :class:`HookimplOpts` used to configure this hook implementation.
|
644 |
| - self.opts = hook_impl_opts |
| 651 | + self.opts: Final = hook_impl_opts |
645 | 652 | #: The name of the plugin which defined this hook implementation.
|
646 |
| - self.plugin_name = plugin_name |
| 653 | + self.plugin_name: Final = plugin_name |
647 | 654 | #: Whether the hook implementation is a :ref:`wrapper <hookwrapper>`.
|
648 |
| - self.wrapper = hook_impl_opts["wrapper"] |
| 655 | + self.wrapper: Final = hook_impl_opts["wrapper"] |
649 | 656 | #: Whether the hook implementation is an :ref:`old-style wrapper
|
650 | 657 | #: <old_style_hookwrappers>`.
|
651 |
| - self.hookwrapper = hook_impl_opts["hookwrapper"] |
| 658 | + self.hookwrapper: Final = hook_impl_opts["hookwrapper"] |
652 | 659 | #: Whether validation against a hook specification is :ref:`optional
|
653 | 660 | #: <optionalhook>`.
|
654 |
| - self.optionalhook = hook_impl_opts["optionalhook"] |
| 661 | + self.optionalhook: Final = hook_impl_opts["optionalhook"] |
655 | 662 | #: Whether to try to order this hook implementation :ref:`first
|
656 | 663 | #: <callorder>`.
|
657 |
| - self.tryfirst = hook_impl_opts["tryfirst"] |
| 664 | + self.tryfirst: Final = hook_impl_opts["tryfirst"] |
658 | 665 | #: Whether to try to order this hook implementation :ref:`last
|
659 | 666 | #: <callorder>`.
|
660 |
| - self.trylast = hook_impl_opts["trylast"] |
| 667 | + self.trylast: Final = hook_impl_opts["trylast"] |
661 | 668 |
|
662 | 669 | def __repr__(self) -> str:
|
663 | 670 | return f"<HookImpl plugin_name={self.plugin_name!r}, plugin={self.plugin!r}>"
|
664 | 671 |
|
665 | 672 |
|
| 673 | +@final |
666 | 674 | class HookSpec:
|
667 | 675 | __slots__ = (
|
668 | 676 | "namespace",
|
|
0 commit comments