From 1bac703c14976e38baba1d194acd413db81bb40d Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Wed, 22 May 2024 12:13:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20Use=20`TypeIs`=20where?= =?UTF-8?q?=20possible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/openforms/config/checks.py | 6 ++++-- src/openforms/formio/utils.py | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/openforms/config/checks.py b/src/openforms/config/checks.py index dfd4bc8d35..f5b58c4b4f 100644 --- a/src/openforms/config/checks.py +++ b/src/openforms/config/checks.py @@ -1,8 +1,10 @@ -from typing import Any, Generator, Protocol, TypeGuard +from typing import Any, Generator, Protocol from django.utils.encoding import force_str from django.utils.translation import gettext as _ +from typing_extensions import TypeIs + from openforms.appointments.registry import register as appointments_register from openforms.contrib.brk.checks import BRKValidatorCheck from openforms.contrib.kadaster.config_check import BAGCheck, LocatieServerCheck @@ -30,7 +32,7 @@ def _subset_match(requested: str | None, checking: str) -> bool: return requested == checking -def is_plugin(plugin: Any) -> TypeGuard[AbstractBasePlugin]: +def is_plugin(plugin: Any) -> TypeIs[AbstractBasePlugin]: if hasattr(plugin, "identifier"): return True return False diff --git a/src/openforms/formio/utils.py b/src/openforms/formio/utils.py index c97d318604..3b5c5612e5 100644 --- a/src/openforms/formio/utils.py +++ b/src/openforms/formio/utils.py @@ -1,9 +1,10 @@ import logging from dataclasses import dataclass -from typing import Any, Callable, Iterator, TypeAlias, TypeGuard +from typing import Any, Callable, Iterator, TypeAlias import elasticapm from glom import Coalesce, Path, glom +from typing_extensions import TypeIs from openforms.typing import DataMapping, JSONObject, JSONValue from openforms.utils.glom import _glom_path_to_str @@ -21,7 +22,7 @@ ) -def _is_column_component(component: ComponentLike) -> TypeGuard[ColumnsComponent]: +def _is_column_component(component: ComponentLike) -> TypeIs[ColumnsComponent]: return component.get("type") == "columns"