@@ -17,19 +17,16 @@ def reactpy_warnings(app_configs, **kwargs):
1717 from reactpy_django .config import REACTPY_FAILED_COMPONENTS
1818
1919 warnings = []
20- INSTALLED_APPS : list [str ] = getattr (settings , "INSTALLED_APPS" , [])
20+ installed_apps : list [str ] = getattr (settings , "INSTALLED_APPS" , [])
2121
2222 # Check if REACTPY_DATABASE is not an in-memory database.
2323 if (
24- getattr (settings , "DATABASES" , {})
25- .get (getattr (settings , "REACTPY_DATABASE" , "default" ), {})
26- .get ("NAME" , None )
24+ getattr (settings , "DATABASES" , {}).get (getattr (settings , "REACTPY_DATABASE" , "default" ), {}).get ("NAME" , None )
2725 == ":memory:"
2826 ):
2927 warnings .append (
3028 Warning (
31- "Using ReactPy with an in-memory database can cause unexpected "
32- "behaviors." ,
29+ "Using ReactPy with an in-memory database can cause unexpected behaviors." ,
3330 hint = "Configure settings.py:DATABASES[REACTPY_DATABASE], to use a "
3431 "multiprocessing and thread safe database." ,
3532 id = "reactpy_django.W001" ,
@@ -52,14 +49,12 @@ def reactpy_warnings(app_configs, **kwargs):
5249 )
5350
5451 # Warn if REACTPY_BACKHAUL_THREAD is set to True with Daphne
55- if (
56- sys .argv [0 ].endswith ("daphne" )
57- or ("runserver" in sys .argv and "daphne" in INSTALLED_APPS )
58- ) and getattr (settings , "REACTPY_BACKHAUL_THREAD" , False ):
52+ if (sys .argv [0 ].endswith ("daphne" ) or ("runserver" in sys .argv and "daphne" in installed_apps )) and getattr (
53+ settings , "REACTPY_BACKHAUL_THREAD" , False
54+ ):
5955 warnings .append (
6056 Warning (
61- "Unstable configuration detected. REACTPY_BACKHAUL_THREAD is enabled "
62- "and you running with Daphne." ,
57+ "Unstable configuration detected. REACTPY_BACKHAUL_THREAD is enabled and you running with Daphne." ,
6358 hint = "Set settings.py:REACTPY_BACKHAUL_THREAD to False or use a different web server." ,
6459 id = "reactpy_django.W003" ,
6560 )
@@ -79,10 +74,8 @@ def reactpy_warnings(app_configs, **kwargs):
7974 if REACTPY_FAILED_COMPONENTS :
8075 warnings .append (
8176 Warning (
82- "ReactPy failed to register the following components:\n \t + "
83- + "\n \t + " .join (REACTPY_FAILED_COMPONENTS ),
84- hint = "Check if these paths are valid, or if an exception is being "
85- "raised during import." ,
77+ "ReactPy failed to register the following components:\n \t + " + "\n \t + " .join (REACTPY_FAILED_COMPONENTS ),
78+ hint = "Check if these paths are valid, or if an exception is being raised during import." ,
8679 id = "reactpy_django.W005" ,
8780 )
8881 )
@@ -106,10 +99,8 @@ def reactpy_warnings(app_configs, **kwargs):
10699
107100 # Check if REACTPY_URL_PREFIX is being used properly in our HTTP URLs
108101 with contextlib .suppress (NoReverseMatch ):
109- full_path = reverse ("reactpy:web_modules" , kwargs = {"file" : "example" }).strip (
110- "/"
111- )
112- reactpy_http_prefix = f'{ full_path [: full_path .find ("web_module/" )].strip ("/" )} '
102+ full_path = reverse ("reactpy:web_modules" , kwargs = {"file" : "example" }).strip ("/" )
103+ reactpy_http_prefix = f"{ full_path [: full_path .find ('web_module/' )].strip ('/' )} "
113104 if reactpy_http_prefix != config .REACTPY_URL_PREFIX :
114105 warnings .append (
115106 Warning (
@@ -138,9 +129,7 @@ def reactpy_warnings(app_configs, **kwargs):
138129 )
139130
140131 # Check if `daphne` is not in installed apps when using `runserver`
141- if "runserver" in sys .argv and "daphne" not in getattr (
142- settings , "INSTALLED_APPS" , []
143- ):
132+ if "runserver" in sys .argv and "daphne" not in getattr (settings , "INSTALLED_APPS" , []):
144133 warnings .append (
145134 Warning (
146135 "You have not configured the `runserver` command to use ASGI. "
@@ -153,10 +142,7 @@ def reactpy_warnings(app_configs, **kwargs):
153142 # DELETED W013: Check if deprecated value REACTPY_RECONNECT_MAX exists
154143
155144 # Check if REACTPY_RECONNECT_INTERVAL is set to a large value
156- if (
157- isinstance (config .REACTPY_RECONNECT_INTERVAL , int )
158- and config .REACTPY_RECONNECT_INTERVAL > 30000
159- ):
145+ if isinstance (config .REACTPY_RECONNECT_INTERVAL , int ) and config .REACTPY_RECONNECT_INTERVAL > 30000 :
160146 warnings .append (
161147 Warning (
162148 "REACTPY_RECONNECT_INTERVAL is set to >30 seconds. Are you sure this is intentional? "
@@ -167,10 +153,7 @@ def reactpy_warnings(app_configs, **kwargs):
167153 )
168154
169155 # Check if REACTPY_RECONNECT_MAX_RETRIES is set to a large value
170- if (
171- isinstance (config .REACTPY_RECONNECT_MAX_RETRIES , int )
172- and config .REACTPY_RECONNECT_MAX_RETRIES > 5000
173- ):
156+ if isinstance (config .REACTPY_RECONNECT_MAX_RETRIES , int ) and config .REACTPY_RECONNECT_MAX_RETRIES > 5000 :
174157 warnings .append (
175158 Warning (
176159 "REACTPY_RECONNECT_MAX_RETRIES is set to a very large value "
@@ -204,18 +187,12 @@ def reactpy_warnings(app_configs, **kwargs):
204187 and config .REACTPY_RECONNECT_MAX_INTERVAL > 0
205188 and config .REACTPY_RECONNECT_MAX_RETRIES > 0
206189 and config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER > 1
207- and (
208- config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER
209- ** config .REACTPY_RECONNECT_MAX_RETRIES
210- )
190+ and (config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER ** config .REACTPY_RECONNECT_MAX_RETRIES )
211191 * config .REACTPY_RECONNECT_INTERVAL
212192 < config .REACTPY_RECONNECT_MAX_INTERVAL
213193 ):
214194 max_value = math .floor (
215- (
216- config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER
217- ** config .REACTPY_RECONNECT_MAX_RETRIES
218- )
195+ (config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER ** config .REACTPY_RECONNECT_MAX_RETRIES )
219196 * config .REACTPY_RECONNECT_INTERVAL
220197 )
221198 warnings .append (
@@ -229,13 +206,10 @@ def reactpy_warnings(app_configs, **kwargs):
229206
230207 # Check if 'reactpy_django' is in the correct position in INSTALLED_APPS
231208 position_to_beat = 0
232- for app in INSTALLED_APPS :
209+ for app in installed_apps :
233210 if app .startswith ("django.contrib." ):
234- position_to_beat = INSTALLED_APPS .index (app )
235- if (
236- "reactpy_django" in INSTALLED_APPS
237- and INSTALLED_APPS .index ("reactpy_django" ) < position_to_beat
238- ):
211+ position_to_beat = installed_apps .index (app )
212+ if "reactpy_django" in installed_apps and installed_apps .index ("reactpy_django" ) < position_to_beat :
239213 warnings .append (
240214 Warning (
241215 "The position of 'reactpy_django' in INSTALLED_APPS is suspicious." ,
@@ -276,17 +250,13 @@ def reactpy_errors(app_configs, **kwargs):
276250 )
277251
278252 # DATABASE_ROUTERS is properly configured when REACTPY_DATABASE is defined
279- if getattr (
280- settings , "REACTPY_DATABASE" , None
281- ) and "reactpy_django.database.Router" not in getattr (
253+ if getattr (settings , "REACTPY_DATABASE" , None ) and "reactpy_django.database.Router" not in getattr (
282254 settings , "DATABASE_ROUTERS" , []
283255 ):
284256 errors .append (
285257 Error (
286- "ReactPy database has been changed but the database router is "
287- "not configured." ,
288- hint = "Set settings.py:DATABASE_ROUTERS to "
289- "['reactpy_django.database.Router', ...]" ,
258+ "ReactPy database has been changed but the database router is not configured." ,
259+ hint = "Set settings.py:DATABASE_ROUTERS to ['reactpy_django.database.Router', ...]" ,
290260 id = "reactpy_django.E002" ,
291261 )
292262 )
@@ -336,9 +306,7 @@ def reactpy_errors(app_configs, **kwargs):
336306 )
337307
338308 # Check if REACTPY_DEFAULT_QUERY_POSTPROCESSOR is a valid data type
339- if not isinstance (
340- getattr (settings , "REACTPY_DEFAULT_QUERY_POSTPROCESSOR" , "" ), (str , type (None ))
341- ):
309+ if not isinstance (getattr (settings , "REACTPY_DEFAULT_QUERY_POSTPROCESSOR" , "" ), (str , type (None ))):
342310 errors .append (
343311 Error (
344312 "Invalid type for REACTPY_DEFAULT_QUERY_POSTPROCESSOR." ,
@@ -397,10 +365,7 @@ def reactpy_errors(app_configs, **kwargs):
397365 )
398366
399367 # Check if REACTPY_RECONNECT_INTERVAL is a positive integer
400- if (
401- isinstance (config .REACTPY_RECONNECT_INTERVAL , int )
402- and config .REACTPY_RECONNECT_INTERVAL < 0
403- ):
368+ if isinstance (config .REACTPY_RECONNECT_INTERVAL , int ) and config .REACTPY_RECONNECT_INTERVAL < 0 :
404369 errors .append (
405370 Error (
406371 "Invalid value for REACTPY_RECONNECT_INTERVAL." ,
@@ -420,10 +385,7 @@ def reactpy_errors(app_configs, **kwargs):
420385 )
421386
422387 # Check if REACTPY_RECONNECT_MAX_INTERVAL is a positive integer
423- if (
424- isinstance (config .REACTPY_RECONNECT_MAX_INTERVAL , int )
425- and config .REACTPY_RECONNECT_MAX_INTERVAL < 0
426- ):
388+ if isinstance (config .REACTPY_RECONNECT_MAX_INTERVAL , int ) and config .REACTPY_RECONNECT_MAX_INTERVAL < 0 :
427389 errors .append (
428390 Error (
429391 "Invalid value for REACTPY_RECONNECT_MAX_INTERVAL." ,
@@ -457,10 +419,7 @@ def reactpy_errors(app_configs, **kwargs):
457419 )
458420
459421 # Check if REACTPY_RECONNECT_MAX_RETRIES is a positive integer
460- if (
461- isinstance (config .REACTPY_RECONNECT_MAX_RETRIES , int )
462- and config .REACTPY_RECONNECT_MAX_RETRIES < 0
463- ):
422+ if isinstance (config .REACTPY_RECONNECT_MAX_RETRIES , int ) and config .REACTPY_RECONNECT_MAX_RETRIES < 0 :
464423 errors .append (
465424 Error (
466425 "Invalid value for REACTPY_RECONNECT_MAX_RETRIES." ,
@@ -523,10 +482,7 @@ def reactpy_errors(app_configs, **kwargs):
523482 )
524483
525484 # Check if REACTPY_CLEAN_INTERVAL is a positive integer
526- if (
527- isinstance (config .REACTPY_CLEAN_INTERVAL , int )
528- and config .REACTPY_CLEAN_INTERVAL < 0
529- ):
485+ if isinstance (config .REACTPY_CLEAN_INTERVAL , int ) and config .REACTPY_CLEAN_INTERVAL < 0 :
530486 errors .append (
531487 Error (
532488 "Invalid value for REACTPY_CLEAN_INTERVAL." ,
0 commit comments