File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ def load_plugins(plugin_apis: list[str]) -> Generator[PluginType]:
46
46
else :
47
47
plugin_instance = plugin_callable
48
48
49
+ # We cannot use isinstance() here since some of the PluginType methods
50
+ # are optional. Instead, we use @abstractmethod decorator to naturally
51
+ # annotate required methods, and the remaining methods are optional.
49
52
required_attributes = PluginType .__abstractmethods__
50
53
if missing_attributes := required_attributes .difference (dir (plugin_instance )):
51
54
raise TypeError (
Original file line number Diff line number Diff line change 7
7
# Must be standalone.
8
8
# =============================================================================== #
9
9
10
+ """
11
+ Protocols for the plugin API
12
+
13
+ This file provides a number of protocols outlining the design of the plugin API.
14
+ The classes serve a dual purpose: they are meant to help plugin authors
15
+ visualize the plugin API, and they can also serve as abstract base classes
16
+ for an actual plugin implementation. This module is intended to be fully
17
+ self-contained and standalone, and it can be easily vendored into a plugin.
18
+
19
+ The central class is PluginType, which defined the API provided by the plugin.
20
+ The actual API can be implemented as regular methods on a class (optionally
21
+ subclassing PluginType), class methods, static methods or top-level functions
22
+ in a module.
23
+
24
+ The methods declared as abstract here must be defined by the plugin.
25
+ The remaining methods are optional. If they are not defined, the caller
26
+ assumes a default value equivalent to the implementation provided in the class.
27
+ This means that plugins do not need to define them even if they do not subclass
28
+ the protocol classes.
29
+ """
30
+
10
31
from __future__ import annotations
11
32
12
33
from abc import abstractmethod
You can’t perform that action at this time.
0 commit comments