Browse Source

Make plugin base classes abstract

Now each plugin base class (PluginBase and Handler) has an abstract
method for the main functionality it provides, forcing plugin authors to
implement those methods before their plugin can be successfully used.
Clara Hobbs 6 years ago
parent
commit
e432e288ea
1 changed files with 8 additions and 3 deletions
  1. 8
    3
      kayleevc/plugins/__init__.py

+ 8
- 3
kayleevc/plugins/__init__.py View File

@@ -3,8 +3,12 @@
3 3
 # Copyright 2015-2017 Clayton G. Hobbs
4 4
 # Portions Copyright 2013 Jezra
5 5
 
6
+"""Builtin Kaylee plugins and base classes"""
6 7
 
7
-class PluginBase():
8
+from abc import ABC, abstractmethod
9
+
10
+
11
+class PluginBase(ABC):
8 12
     """Base class for Kaylee plugins
9 13
 
10 14
     Each Kaylee plugin module must define a subclass of this class, named
@@ -25,6 +29,7 @@ class PluginBase():
25 29
         self.options = config.plugins[name]
26 30
         self.corpus_strings = set()
27 31
 
32
+    @abstractmethod
28 33
     def get_handler(self, text):
29 34
         """Return a handler for the given text
30 35
 
@@ -34,10 +39,9 @@ class PluginBase():
34 39
         the command is recognized, but for some reason would not perform any
35 40
         action currently, e.g. "pause music" when no music player is running.
36 41
         """
37
-        return None
38 42
 
39 43
 
40
-class Handler:
44
+class Handler(ABC):
41 45
     """Base class for Kaylee plugin handlers
42 46
 
43 47
     Plugins should subclass this for their own command handlers.
@@ -60,6 +64,7 @@ class Handler:
60 64
         """
61 65
         self.confidence = confidence
62 66
 
67
+    @abstractmethod
63 68
     def __call__(self, tts):
64 69
         """Handle the command
65 70
 

Loading…
Cancel
Save