Skip to content

Commit

Permalink
🏷️ Improve type hints for get_config_actions in (base) plugins
Browse files Browse the repository at this point in the history
The Sequence is covariant (which the list isn't), which helps in
inferring in concrete classes without getting errors about mismatching
signatures between parent and subclass.
  • Loading branch information
sergei-maertens committed Jul 1, 2024
1 parent 6b28ae1 commit 8638b32
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/openforms/config/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from django.contrib.admin.templatetags.admin_list import _boolean_icon

Action: TypeAlias = tuple[str, str]
from openforms.typing import _StrOrPromise

Action: TypeAlias = tuple[_StrOrPromise, str] # (label, reversed URL path)


@dataclass
Expand Down
5 changes: 4 additions & 1 deletion src/openforms/plugins/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from collections.abc import Sequence

from django.utils.translation import gettext_lazy as _

from openforms.config.data import Action
from openforms.config.models import GlobalConfiguration

from .registry import BaseRegistry
Expand Down Expand Up @@ -43,7 +46,7 @@ def check_config(self):
"""
raise NotImplementedError()

def get_config_actions(self) -> list[tuple[str, str]]:
def get_config_actions(self) -> Sequence[Action]:
"""
Returns a list of tuples containing the label and URL of each action
that is related to the configuration of this plugin. This can be to
Expand Down
5 changes: 3 additions & 2 deletions src/openforms/prefill/contrib/demo/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.utils.crypto import get_random_string
from django.utils.translation import gettext_lazy as _

from openforms.config.data import Action
from openforms.submissions.models import Submission

from ...base import BasePlugin
Expand Down Expand Up @@ -44,8 +45,8 @@ def get_prefill_values(
"""
return {attr: CALLBACKS[attr]() for attr in attributes}

def check_config(self):
def check_config(self) -> list[Action]:
"""
Demo config is always valid.
"""
pass
return []

0 comments on commit 8638b32

Please sign in to comment.