From 46d8d4322ed3db3e1e07eeb13bc6a6b6bc538895 Mon Sep 17 00:00:00 2001 From: chewingbever Date: Wed, 26 Aug 2020 13:05:56 +0200 Subject: [PATCH] RegexCommand's now get matched last --- frank/module/meta.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frank/module/meta.py b/frank/module/meta.py index c78aac6..c488b7e 100644 --- a/frank/module/meta.py +++ b/frank/module/meta.py @@ -6,7 +6,7 @@ from __future__ import annotations from functools import cached_property # Own imports -from .decorators import Command, Daemon, Default +from .decorators import Command, Daemon, Default, RegexCommand # Typing imports from typing import TYPE_CHECKING @@ -33,8 +33,11 @@ class ModuleMeta: @cached_property def commands(self) -> List[Command]: # This also matches RegexCommand objects - # TODO: sort this to put RegexCommand's at the back - return self._filter_attrs(lambda val: isinstance(val, Command)) + # The sort puts all the RegexCommand objects at the back, making them + # be matched last + + return sorted(self._filter_attrs(lambda val: isinstance(val, Command)), + key=lambda x: isinstance(x, RegexCommand)) @cached_property def daemons(self) -> List[Daemon]: