diff options
author | mathieui <mathieui@mathieui.net> | 2016-08-21 15:27:53 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2016-08-21 15:39:30 +0200 |
commit | 84e59b05ff0a17178da9ecdb6c5d084e48b42763 (patch) | |
tree | 224948d7c3d49a0005bff9390260357b3ec9c60e /poezio/core/structs.py | |
parent | 6c270b363ac018dfd4d66b23af95efcc35610da0 (diff) | |
download | poezio-84e59b05ff0a17178da9ecdb6c5d084e48b42763.tar.gz poezio-84e59b05ff0a17178da9ecdb6c5d084e48b42763.tar.bz2 poezio-84e59b05ff0a17178da9ecdb6c5d084e48b42763.tar.xz poezio-84e59b05ff0a17178da9ecdb6c5d084e48b42763.zip |
Don’t call input completion() functions inside completion methods
Use a placeholder object that can run it afterwards, so that we don’t
have side effects inside those functions.
Diffstat (limited to 'poezio/core/structs.py')
-rw-r--r-- | poezio/core/structs.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/poezio/core/structs.py b/poezio/core/structs.py index 82effd48..7d568f04 100644 --- a/poezio/core/structs.py +++ b/poezio/core/structs.py @@ -3,7 +3,7 @@ Module defining structures useful to the core class and related methods """ __all__ = ['ERROR_AND_STATUS_CODES', 'DEPRECATED_ERRORS', 'POSSIBLE_SHOW', - 'Status', 'Command'] + 'Status', 'Command', 'Completion'] # http://xmpp.org/extensions/xep-0045.html#errorstatus ERROR_AND_STATUS_CODES = { @@ -62,3 +62,17 @@ class Command: self.comp = comp self.short_desc = short_desc self.usage = usage + +class Completion: + """ + A completion result essentially currying the input completion call. + """ + __slots__ = ['func', 'args', 'kwargs', 'comp_list'] + def __init__(self, func, comp_list, *args, **kwargs): + self.func = func + self.comp_list = comp_list + self.args = args + self.kwargs = kwargs + + def run(self): + return self.func(self.comp_list, *self.args, **self.kwargs) |