32
32
from django .forms import Form , ModelForm
33
33
from django .views import View
34
34
35
- from reactpy_django .types import AsyncFormEvent , SyncFormEvent
35
+ from reactpy_django .types import AsyncFormEvent , SyncFormEvent , ViewToComponentConstructor , ViewToIframeConstructor
36
36
37
37
38
38
def view_to_component (
39
39
view : Callable | View | str ,
40
40
transforms : Sequence [Callable [[VdomDict ], Any ]] = (),
41
41
strict_parsing : bool = True ,
42
- ) -> Any :
42
+ ) -> ViewToComponentConstructor :
43
43
"""Converts a Django view to a ReactPy component.
44
44
45
45
Keyword Args:
@@ -58,7 +58,7 @@ def constructor(
58
58
* args ,
59
59
key : Key | None = None ,
60
60
** kwargs ,
61
- ):
61
+ ) -> ComponentType :
62
62
return _view_to_component (
63
63
view = view ,
64
64
transforms = transforms ,
@@ -72,7 +72,7 @@ def constructor(
72
72
return constructor
73
73
74
74
75
- def view_to_iframe (view : Callable | View | str , extra_props : dict [str , Any ] | None = None ):
75
+ def view_to_iframe (view : Callable | View | str , extra_props : dict [str , Any ] | None = None ) -> ViewToIframeConstructor :
76
76
"""
77
77
Args:
78
78
view: The view function or class to convert, or the dotted path to the view.
@@ -88,13 +88,13 @@ def constructor(
88
88
* args ,
89
89
key : Key | None = None ,
90
90
** kwargs ,
91
- ):
91
+ ) -> ComponentType :
92
92
return _view_to_iframe (view = view , extra_props = extra_props , args = args , kwargs = kwargs , key = key )
93
93
94
94
return constructor
95
95
96
96
97
- def django_css (static_path : str , key : Key | None = None ):
97
+ def django_css (static_path : str , key : Key | None = None ) -> ComponentType :
98
98
"""Fetches a CSS static file for use within ReactPy. This allows for deferred CSS loading.
99
99
100
100
Args:
@@ -107,7 +107,7 @@ def django_css(static_path: str, key: Key | None = None):
107
107
return _django_css (static_path = static_path , key = key )
108
108
109
109
110
- def django_js (static_path : str , key : Key | None = None ):
110
+ def django_js (static_path : str , key : Key | None = None ) -> ComponentType :
111
111
"""Fetches a JS static file for use within ReactPy. This allows for deferred JS loading.
112
112
113
113
Args:
@@ -135,7 +135,7 @@ def django_form(
135
135
top_children : Sequence [Any ] = (),
136
136
bottom_children : Sequence [Any ] = (),
137
137
key : Key | None = None ,
138
- ):
138
+ ) -> ComponentType :
139
139
"""Converts a Django form to a ReactPy component.
140
140
141
141
Args:
@@ -182,7 +182,7 @@ def pyscript_component(
182
182
* file_paths : str ,
183
183
initial : str | VdomDict | ComponentType = "" ,
184
184
root : str = "root" ,
185
- ):
185
+ ) -> ComponentType :
186
186
"""
187
187
Args:
188
188
file_paths: File path to your client-side component. If multiple paths are \
@@ -219,7 +219,7 @@ def _view_to_component(
219
219
else :
220
220
_request = HttpRequest ()
221
221
_request .method = "GET"
222
- resolved_view : Callable = import_module (view ) if isinstance (view , str ) else view
222
+ resolved_view : Callable = import_module (view ) if isinstance (view , str ) else view # type: ignore
223
223
224
224
# Render the view render within a hook
225
225
@hooks .use_effect (
@@ -251,12 +251,12 @@ def _view_to_iframe(
251
251
extra_props : dict [str , Any ] | None ,
252
252
args : Sequence ,
253
253
kwargs : dict ,
254
- ) -> VdomDict :
254
+ ):
255
255
"""The actual component. Used to prevent pollution of acceptable kwargs keys."""
256
256
from reactpy_django .config import REACTPY_REGISTERED_IFRAME_VIEWS
257
257
258
258
if hasattr (view , "view_class" ):
259
- view = view .view_class
259
+ view = view .view_class # type: ignore
260
260
dotted_path = view if isinstance (view , str ) else generate_obj_name (view )
261
261
registered_view = REACTPY_REGISTERED_IFRAME_VIEWS .get (dotted_path )
262
262
0 commit comments