Skip to content

Commit

Permalink
refactor: disallow TranslatableStrings in form element and condition …
Browse files Browse the repository at this point in the history
…values
  • Loading branch information
MHajoha committed Mar 4, 2025
1 parent 98d73a2 commit 12cb709
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ python = "^3.11"
aiohttp = "^3.9.3"
pydantic = "^2.6.4"
PyYAML = "^6.0.1"
questionpy-server = { git = "https://github.com/questionpy-org/questionpy-server.git", rev = "2c8e0ae7d6e0387db64c86edc439cc39ca8da71a" }
questionpy-server = { git = "https://github.com/questionpy-org/questionpy-server.git", rev = "e76d8e6b24ebac872e94e19928c0785f4a84608b" }
jinja2 = "^3.1.3"
aiohttp-jinja2 = "^1.6"
lxml = {version = "~5.3.0", extras = ["html_clean"]}
Expand Down
12 changes: 5 additions & 7 deletions questionpy/form/_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,7 @@ def select(
)


def option(
label: str | TranslatableString, *, selected: bool = False, value: str | TranslatableString | None = None
) -> _OptionInfo:
def option(label: str | TranslatableString, *, selected: bool = False, value: str | None = None) -> _OptionInfo:
"""Adds an option to an [`OptionEnum`][questionpy.form.OptionEnum].
Args:
Expand Down Expand Up @@ -625,7 +623,7 @@ def hidden(value: _S, *, disable_if: _ZeroOrMoreConditions = None, hide_if: _Zer
"""Adds a hidden element with a fixed value.
Args:
value (str | TranslatableString): Fixed value.
value (str): Fixed value.
disable_if (Condition | list[Condition] | None): Disable this element if some condition(s) match.
hide_if (Condition | list[Condition] | None): Hide this element if some condition(s) match.
Expand Down Expand Up @@ -838,7 +836,7 @@ def is_not_checked(name: str) -> IsNotChecked:
return IsNotChecked(name=name)


def equals(name: str, *, value: str | TranslatableString | int | bool) -> Equals:
def equals(name: str, *, value: str | int | bool) -> Equals:
"""Condition on the value of another field being equal to some static value.
Many elements can be hidden or disabled client-side by passing conditions to `hide_if` or `disable_if`. See the
Expand All @@ -862,7 +860,7 @@ def equals(name: str, *, value: str | TranslatableString | int | bool) -> Equals
return Equals(name=name, value=value)


def does_not_equal(name: str, *, value: str | TranslatableString | int | bool) -> DoesNotEqual:
def does_not_equal(name: str, *, value: str | int | bool) -> DoesNotEqual:
"""Condition on the value of another field *not* being equal to some static value.
Many elements can be hidden or disabled client-side by passing conditions to `hide_if` or `disable_if`. See the
Expand Down Expand Up @@ -890,7 +888,7 @@ def does_not_equal(name: str, *, value: str | TranslatableString | int | bool) -
return DoesNotEqual(name=name, value=value)


def is_in(name: str, values: list[str | TranslatableString | int | bool]) -> In:
def is_in(name: str, values: list[str | int | bool]) -> In:
"""Condition on the value of another field being one of a number of static values.
Many elements can be hidden or disabled client-side by passing conditions to `hide_if` or `disable_if`. See the
Expand Down
2 changes: 1 addition & 1 deletion questionpy/form/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class _OptionInfo:
label: str | TranslatableString
selected: bool
value: str | TranslatableString | None = None
value: str | None = None
"""If None, set to the name by `OptionEnum.__init__` because __set_name__ doesn't get called for enum members."""


Expand Down

0 comments on commit 12cb709

Please sign in to comment.