Skip to content

Commit

Permalink
🏷️ [#4689] Fix type definitions / add type definitions
Browse files Browse the repository at this point in the history
Fixed/added some type definitions to make it easier to reason about
the data being operated on.
  • Loading branch information
sergei-maertens committed Jan 31, 2025
1 parent e3b3634 commit 9e456e6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/openforms/formio/typing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
EditGridComponent,
FieldsetComponent,
FileComponent,
FileValue,
RadioComponent,
SelectBoxesComponent,
SelectComponent,
Expand All @@ -31,6 +32,7 @@
"TextFieldComponent",
"DateComponent",
"DatetimeComponent",
"FileValue",
"FileComponent",
"SelectComponent",
"SelectBoxesComponent",
Expand Down
23 changes: 23 additions & 0 deletions src/openforms/formio/typing/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ class FileComponent(Component):
maxNumberOfFiles: NotRequired[int]


class FileData(TypedDict):
url: str
form: Literal[""]
name: str
size: int
baseUrl: str
project: Literal[""]


class SingleFileValue(TypedDict):
# Source of truth: https://github.com/open-formulieren/types/blob/main/src/formio/components/file.ts
name: str
originalName: str
size: int
storage: Literal["url"]
type: str
url: str
data: FileData


type FileValue = list[SingleFileValue]


class SelectData(TypedDict, total=False):
values: list[OptionDict]

Expand Down
4 changes: 2 additions & 2 deletions src/openforms/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
import decimal
import uuid
from typing import TYPE_CHECKING, Any, NewType, Protocol
from typing import TYPE_CHECKING, Any, NewType, Protocol, Sequence

from django.http import HttpRequest
from django.http.response import HttpResponseBase
Expand All @@ -18,7 +18,7 @@

type JSONPrimitive = str | int | float | bool | None

type JSONValue = JSONPrimitive | JSONObject | list[JSONValue]
type JSONValue = JSONPrimitive | JSONObject | Sequence[JSONValue]

type JSONObject = dict[str, JSONValue]

Expand Down

0 comments on commit 9e456e6

Please sign in to comment.