Skip to content

Commit

Permalink
[#3607] PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Jan 8, 2024
1 parent 8d8d4b7 commit e912b76
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/openforms/validations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

from openforms.plugins.plugin import AbstractBasePlugin
from openforms.submissions.models import Submission
from openforms.typing import JSONValue

T = TypeVar("T", default=str)
T = TypeVar("T", bound=JSONValue, default=str)
"""A type variable representing the type of the value being validated by the plugin."""


Expand Down
9 changes: 5 additions & 4 deletions src/openforms/validations/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

from openforms.plugins.registry import BaseRegistry
from openforms.submissions.models import Submission
from openforms.typing import JSONValue

from .base import BasePlugin

logger = logging.getLogger(__name__)

T = TypeVar("T", default=str)
T = TypeVar("T")


@dataclasses.dataclass()
Expand All @@ -40,7 +41,7 @@ def _flat(it):
return list(_flat(iterables))


class Registry(BaseRegistry[BasePlugin[T]]):
class Registry(BaseRegistry[BasePlugin[JSONValue]]):
"""
A registry for the validations module plugins.
Expand All @@ -54,7 +55,7 @@ class Registry(BaseRegistry[BasePlugin[T]]):

@elasticapm.capture_span("app.validations.validate")
def validate(
self, plugin_id: str, value: T, submission: Submission
self, plugin_id: str, value: JSONValue, submission: Submission
) -> ValidationResult:
try:
validator = self._registry[plugin_id]
Expand All @@ -69,7 +70,7 @@ def validate(
],
)

if not getattr(validator, "is_enabled", True):
if not validator.is_enabled:
return ValidationResult(
False,
messages=[
Expand Down
8 changes: 5 additions & 3 deletions src/openforms/validations/validators/formats.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING

Expand All @@ -20,7 +22,7 @@ class PhoneNumberBaseValidator(ABC):
error_message = _("Not a valid %(country)s phone number")

@abstractmethod
def _parse_phonenumber(self, value: str) -> "PhoneNumber":
def _parse_phonenumber(self, value: str) -> PhoneNumber:
pass

Check warning on line 26 in src/openforms/validations/validators/formats.py

View check run for this annotation

Codecov / codecov/patch

src/openforms/validations/validators/formats.py#L26

Added line #L26 was not covered by tests

def __call__(self, value: str, submission):
Expand Down Expand Up @@ -58,7 +60,7 @@ class InternationalPhoneNumberValidator(PhoneNumberBaseValidator, BasePlugin[str
verbose_name = _("International phone number")
for_components = ("phoneNumber",)

def _parse_phonenumber(self, value: str) -> "PhoneNumber":
def _parse_phonenumber(self, value: str) -> PhoneNumber:
try:
return phonenumbers.parse(value, self.country)
except NumberParseException:
Expand All @@ -84,7 +86,7 @@ class DutchPhoneNumberValidator(PhoneNumberBaseValidator, BasePlugin[str]):
verbose_name = _("Dutch phone number")
for_components = ("phoneNumber",)

def _parse_phonenumber(self, value: str) -> "PhoneNumber":
def _parse_phonenumber(self, value: str) -> PhoneNumber:
try:
return phonenumbers.parse(value, self.country)
except NumberParseException:
Expand Down

0 comments on commit e912b76

Please sign in to comment.