From 06bfc120ab59c3ac3d40a18029bb952688cf2595 Mon Sep 17 00:00:00 2001 From: Richard Ebeling Date: Mon, 26 Feb 2024 17:48:09 +0100 Subject: [PATCH] Fix django-stubs-ext missing breaking a production setup (#2110) Make django-stubs a non-dev-requirement. Just make StrOrPromise = Any if we're not typechecking. Use strict StrOrPromise with typeguard --- evap/evaluation/models.py | 2 +- evap/evaluation/tools.py | 11 +++++++++-- evap/staff/views.py | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/evap/evaluation/models.py b/evap/evaluation/models.py index bc1d3cba17..a7601e4a64 100644 --- a/evap/evaluation/models.py +++ b/evap/evaluation/models.py @@ -30,10 +30,10 @@ from django.utils.translation import gettext_lazy as _ from django_fsm import FSMIntegerField, transition from django_fsm.signals import post_transition -from django_stubs_ext import StrOrPromise from evap.evaluation.models_logging import FieldAction, LoggedModel from evap.evaluation.tools import ( + StrOrPromise, clean_email, date_to_datetime, is_external_email, diff --git a/evap/evaluation/tools.py b/evap/evaluation/tools.py index ad9aa51a7f..9012ccedce 100644 --- a/evap/evaluation/tools.py +++ b/evap/evaluation/tools.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from collections import defaultdict from collections.abc import Iterable, Mapping -from typing import Any, Protocol, TypeVar +from typing import TYPE_CHECKING, Any, Protocol, TypeVar from urllib.parse import quote import xlwt @@ -16,7 +16,14 @@ from django.utils.datastructures import MultiValueDict from django.utils.translation import get_language from django.views.generic import FormView -from django_stubs_ext import StrOrPromise + +if TYPE_CHECKING: + from django_stubs_ext import StrOrPromise # use proper definition with mypy +else: + try: + from django_stubs_ext import StrOrPromise # if installed, use proper definition for typeguard + except ImportError: + StrOrPromise = Any # on production setups, type alias to Any M = TypeVar("M", bound=Model) T = TypeVar("T") diff --git a/evap/staff/views.py b/evap/staff/views.py index c9a8f7ddb1..df1b5e3be2 100644 --- a/evap/staff/views.py +++ b/evap/staff/views.py @@ -37,7 +37,6 @@ from django.utils.translation import gettext_lazy, ngettext from django.views.decorators.http import require_POST from django.views.generic import CreateView, FormView, UpdateView -from django_stubs_ext import StrOrPromise from evap.contributor.views import export_contributor_results from evap.evaluation.auth import manager_required, reviewer_required, staff_permission_required @@ -65,6 +64,7 @@ FormsetView, HttpResponseNoContent, SaveValidFormMixin, + StrOrPromise, get_object_from_dict_pk_entry_or_logged_40x, get_parameter_from_url_or_session, sort_formset,