1515import warnings
1616from collections .abc import Awaitable , Coroutine , Sequence
1717from http .client import responses
18- from logging import Logger
1918from typing import TYPE_CHECKING , Any , cast
2019from urllib .parse import urlparse
2120
4443)
4544
4645if TYPE_CHECKING :
46+ from logging import Logger
47+
4748 from jupyter_client .kernelspec import KernelSpecManager
4849 from jupyter_events import EventLogger
4950 from jupyter_server_terminals .terminalmanager import TerminalManager
@@ -75,7 +76,7 @@ def json_sys_info():
7576def log () -> Logger :
7677 """Get the application log."""
7778 if Application .initialized ():
78- return cast (Logger , Application .instance ().log )
79+ return cast (" Logger" , Application .instance ().log )
7980 else :
8081 return app_log
8182
@@ -85,7 +86,7 @@ class AuthenticatedHandler(web.RequestHandler):
8586
8687 @property
8788 def base_url (self ) -> str :
88- return cast (str , self .settings .get ("base_url" , "/" ))
89+ return cast (" str" , self .settings .get ("base_url" , "/" ))
8990
9091 @property
9192 def content_security_policy (self ) -> str :
@@ -95,7 +96,7 @@ def content_security_policy(self) -> str:
9596 """
9697 if "Content-Security-Policy" in self .settings .get ("headers" , {}):
9798 # user-specified, don't override
98- return cast (str , self .settings ["headers" ]["Content-Security-Policy" ])
99+ return cast (" str" , self .settings ["headers" ]["Content-Security-Policy" ])
99100
100101 return "; " .join (
101102 [
@@ -173,7 +174,7 @@ def get_current_user(self) -> str:
173174 DeprecationWarning ,
174175 stacklevel = 2 ,
175176 )
176- return cast (str , self ._jupyter_current_user )
177+ return cast (" str" , self ._jupyter_current_user )
177178 # haven't called get_user in prepare, raise
178179 raise RuntimeError (msg )
179180
@@ -224,7 +225,7 @@ def login_available(self) -> bool:
224225 whether the user is already logged in or not.
225226
226227 """
227- return cast (bool , self .identity_provider .login_available )
228+ return cast (" bool" , self .identity_provider .login_available )
228229
229230 @property
230231 def authorizer (self ) -> Authorizer :
@@ -302,34 +303,34 @@ def serverapp(self) -> ServerApp | None:
302303 @property
303304 def version_hash (self ) -> str :
304305 """The version hash to use for cache hints for static files"""
305- return cast (str , self .settings .get ("version_hash" , "" ))
306+ return cast (" str" , self .settings .get ("version_hash" , "" ))
306307
307308 @property
308309 def mathjax_url (self ) -> str :
309- url = cast (str , self .settings .get ("mathjax_url" , "" ))
310+ url = cast (" str" , self .settings .get ("mathjax_url" , "" ))
310311 if not url or url_is_absolute (url ):
311312 return url
312313 return url_path_join (self .base_url , url )
313314
314315 @property
315316 def mathjax_config (self ) -> str :
316- return cast (str , self .settings .get ("mathjax_config" , "TeX-AMS-MML_HTMLorMML-full,Safe" ))
317+ return cast (" str" , self .settings .get ("mathjax_config" , "TeX-AMS-MML_HTMLorMML-full,Safe" ))
317318
318319 @property
319320 def default_url (self ) -> str :
320- return cast (str , self .settings .get ("default_url" , "" ))
321+ return cast (" str" , self .settings .get ("default_url" , "" ))
321322
322323 @property
323324 def ws_url (self ) -> str :
324- return cast (str , self .settings .get ("websocket_url" , "" ))
325+ return cast (" str" , self .settings .get ("websocket_url" , "" ))
325326
326327 @property
327328 def contents_js_source (self ) -> str :
328329 self .log .debug (
329330 "Using contents: %s" ,
330331 self .settings .get ("contents_js_source" , "services/contents" ),
331332 )
332- return cast (str , self .settings .get ("contents_js_source" , "services/contents" ))
333+ return cast (" str" , self .settings .get ("contents_js_source" , "services/contents" ))
333334
334335 # ---------------------------------------------------------------
335336 # Manager objects
@@ -370,7 +371,7 @@ def event_logger(self) -> EventLogger:
370371 @property
371372 def allow_origin (self ) -> str :
372373 """Normal Access-Control-Allow-Origin"""
373- return cast (str , self .settings .get ("allow_origin" , "" ))
374+ return cast (" str" , self .settings .get ("allow_origin" , "" ))
374375
375376 @property
376377 def allow_origin_pat (self ) -> str | None :
@@ -380,7 +381,7 @@ def allow_origin_pat(self) -> str | None:
380381 @property
381382 def allow_credentials (self ) -> bool :
382383 """Whether to set Access-Control-Allow-Credentials"""
383- return cast (bool , self .settings .get ("allow_credentials" , False ))
384+ return cast (" bool" , self .settings .get ("allow_credentials" , False ))
384385
385386 def set_default_headers (self ) -> None :
386387 """Add CORS headers, if defined"""
@@ -774,7 +775,7 @@ def write_error(self, status_code: int, **kwargs: Any) -> None:
774775 # backward-compatibility: traceback field is present,
775776 # but always empty
776777 reply ["traceback" ] = ""
777- self .log .warning ("wrote error: %r" , reply ["message" ], exc_info = True )
778+ self .log .warning ("wrote error: %r" , reply ["message" ])
778779 self .finish (json .dumps (reply ))
779780
780781 def get_login_url (self ) -> str :
@@ -1060,7 +1061,7 @@ def validate_absolute_path(self, root: str, absolute_path: str) -> str | None:
10601061 if not absolute_path :
10611062 raise web .HTTPError (404 )
10621063
1063- for root in self .root :
1064+ for root in self .root : # noqa: PLR1704
10641065 if (absolute_path + os .sep ).startswith (root ):
10651066 break
10661067
@@ -1115,7 +1116,7 @@ class FilesRedirectHandler(JupyterHandler):
11151116 """Handler for redirecting relative URLs to the /files/ handler"""
11161117
11171118 @staticmethod
1118- async def redirect_to_files (self : Any , path : str ) -> None :
1119+ async def redirect_to_files (self : Any , path : str ) -> None : # noqa: PLW0211
11191120 """make redirect logic a reusable static method
11201121
11211122 so it can be called from other handlers.
0 commit comments