From 7676a7a3c85bf2a223f43b505c48fbec82d5ab06 Mon Sep 17 00:00:00 2001 From: dgw Date: Sat, 11 Nov 2023 01:33:06 -0600 Subject: [PATCH 1/2] plugin: type-hint `priority` argument as `Literal[]` This will flag any use of unrecognized values for the callable priority. It makes a good intermediate step between the current free-form `str` accepted and probably turning it into an `Enum` later. --- sopel/plugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sopel/plugin.py b/sopel/plugin.py index 6e54bd801..ccb04de20 100644 --- a/sopel/plugin.py +++ b/sopel/plugin.py @@ -15,6 +15,7 @@ import re from typing import ( Callable, + Literal, Optional, Pattern, Protocol, @@ -1011,7 +1012,7 @@ def add_attribute(function): return add_attribute -def priority(value: str) -> Callable: +def priority(value: Literal['low', 'medium', 'high']) -> Callable: """Decorate a function to be executed with higher or lower priority. :param value: one of ``high``, ``medium``, or ``low``; defaults to ``medium`` From 1196b195061d7403a2633074858a6d3250d85fba Mon Sep 17 00:00:00 2001 From: dgw Date: Sat, 11 Nov 2023 15:29:05 -0600 Subject: [PATCH 2/2] plugin: improve `priority` docstring clarity --- sopel/plugin.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sopel/plugin.py b/sopel/plugin.py index ccb04de20..7930dd57a 100644 --- a/sopel/plugin.py +++ b/sopel/plugin.py @@ -1015,10 +1015,11 @@ def add_attribute(function): def priority(value: Literal['low', 'medium', 'high']) -> Callable: """Decorate a function to be executed with higher or lower priority. - :param value: one of ``high``, ``medium``, or ``low``; defaults to ``medium`` + :param value: one of ``high``, ``medium``, or ``low`` - The priority allows you to control the order of callable execution, if your - plugin needs it. + The priority allows you some control over the order of callable execution, + if your plugin needs it. If a callable does not specify its ``priority``, + Sopel assumes ``medium``. """ def add_attribute(function): function.priority = value