Skip to content

Commit

Permalink
Fix django-stubs-ext missing breaking a production setup (#2110)
Browse files Browse the repository at this point in the history
Make django-stubs a non-dev-requirement. Just make StrOrPromise = Any if we're not typechecking. Use strict StrOrPromise with typeguard
  • Loading branch information
richardebeling authored Feb 26, 2024
1 parent 21bd711 commit 06bfc12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions evap/evaluation/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion evap/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 06bfc12

Please sign in to comment.