33import json
44import os
55from pathlib import Path
6- from typing import TYPE_CHECKING , Any , Callable , Type , Union , cast
6+ from typing import TYPE_CHECKING , Any , Callable , Union , cast
77from urllib .parse import urlencode
88from uuid import uuid4
99
@@ -129,7 +129,7 @@ def django_js(static_path: str, key: Key | None = None):
129129
130130
131131def django_form (
132- form : Type [Form ],
132+ form : type [Form ],
133133 * ,
134134 top_children : Sequence = (),
135135 bottom_children : Sequence = (),
@@ -265,7 +265,7 @@ def _django_js(static_path: str):
265265
266266@component
267267def _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
269269):
270270 # TODO: Implement form restoration on page reload. Probably want to create a new setting called
271271 # form_restoration_method that can be set to "URL", "CLIENT_STORAGE", "SERVER_SESSION", or None.
@@ -284,18 +284,20 @@ def _django_form(
284284
285285 # Don't allow the count of top and bottom children to change
286286 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 )
288289
289290 # Try to initialize the form with the provided data
290291 try :
291292 initialized_form = form (data = submitted_data )
292293 except Exception as e :
293294 if not isinstance (form , type (Form )):
294- raise ValueError (
295+ msg = (
295296 "The provided form must be an uninitialized Django Form. "
296297 "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
299301
300302 # Run the form validation, if data was provided
301303 if submitted_data :
0 commit comments