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

Loading…
Cancel
Save