3
3
import json
4
4
import os
5
5
from pathlib import Path
6
- from typing import TYPE_CHECKING , Any , Callable , Type , Union , cast
6
+ from typing import TYPE_CHECKING , Any , Callable , Union , cast
7
7
from urllib .parse import urlencode
8
8
from uuid import uuid4
9
9
@@ -129,7 +129,7 @@ def django_js(static_path: str, key: Key | None = None):
129
129
130
130
131
131
def django_form (
132
- form : Type [Form ],
132
+ form : type [Form ],
133
133
* ,
134
134
top_children : Sequence = (),
135
135
bottom_children : Sequence = (),
@@ -265,7 +265,7 @@ def _django_js(static_path: str):
265
265
266
266
@component
267
267
def _django_form (
268
- form : Type [Form ], top_children : Sequence , bottom_children : Sequence , auto_submit : bool , auto_submit_wait : int
268
+ form : type [Form ], top_children : Sequence , bottom_children : Sequence , auto_submit : bool , auto_submit_wait : int
269
269
):
270
270
# TODO: Implement form restoration on page reload. Probably want to create a new setting called
271
271
# form_restoration_method that can be set to "URL", "CLIENT_STORAGE", "SERVER_SESSION", or None.
@@ -284,18 +284,20 @@ def _django_form(
284
284
285
285
# Don't allow the count of top and bottom children to change
286
286
if len (top_children ) != top_children_count .current or len (bottom_children ) != bottom_children_count .current :
287
- raise ValueError ("Dynamically changing the number of top or bottom children is not allowed." )
287
+ msg = "Dynamically changing the number of top or bottom children is not allowed."
288
+ raise ValueError (msg )
288
289
289
290
# Try to initialize the form with the provided data
290
291
try :
291
292
initialized_form = form (data = submitted_data )
292
293
except Exception as e :
293
294
if not isinstance (form , type (Form )):
294
- raise ValueError (
295
+ msg = (
295
296
"The provided form must be an uninitialized Django Form. "
296
297
"Do NOT initialize your form by calling it (ex. `MyForm()`)."
297
- ) from e
298
- raise e
298
+ )
299
+ raise TypeError (msg ) from e
300
+ raise
299
301
300
302
# Run the form validation, if data was provided
301
303
if submitted_data :
0 commit comments