@@ -473,9 +473,8 @@ def set_qt_api_env_from_gui(gui):
473473 }
474474 if loaded is not None and gui != 'qt' :
475475 if qt_env2gui [loaded ] != gui :
476- raise ImportError (
477- f'Cannot switch Qt versions for this session; must use { qt_env2gui [loaded ]} .'
478- )
476+ msg = f'Cannot switch Qt versions for this session; must use { qt_env2gui [loaded ]} .'
477+ raise ImportError (msg )
479478
480479 if qt_api is not None and gui != 'qt' :
481480 if qt_env2gui [qt_api ] != gui :
@@ -526,9 +525,8 @@ def set_qt_api_env_from_gui(gui):
526525 if 'QT_API' in os .environ .keys ():
527526 del os .environ ['QT_API' ]
528527 else :
529- raise ValueError (
530- f'Unrecognized Qt version: { gui } . Should be "qt4", "qt5", "qt6", or "qt".'
531- )
528+ msg = f'Unrecognized Qt version: { gui } . Should be "qt4", "qt5", "qt6", or "qt".'
529+ raise ValueError (msg )
532530
533531 # Do the actual import now that the environment variable is set to make sure it works.
534532 try :
@@ -543,7 +541,8 @@ def set_qt_api_env_from_gui(gui):
543541def make_qt_app_for_kernel (gui , kernel ):
544542 """Sets the `QT_API` environment variable if it isn't already set."""
545543 if hasattr (kernel , 'app' ):
546- raise RuntimeError ('Kernel already running a Qt event loop.' )
544+ msg = 'Kernel already running a Qt event loop.'
545+ raise RuntimeError (msg )
547546
548547 set_qt_api_env_from_gui (gui )
549548 # This import is guaranteed to work now:
@@ -566,10 +565,11 @@ def enable_gui(gui, kernel=None):
566565 if Application .initialized ():
567566 kernel = getattr (Application .instance (), "kernel" , None )
568567 if kernel is None :
569- raise RuntimeError (
568+ msg = (
570569 "You didn't specify a kernel,"
571570 " and no IPython Application with a kernel appears to be running."
572571 )
572+ raise RuntimeError (msg )
573573 if gui is None :
574574 # User wants to turn off integration; clear any evidence if Qt was the last one.
575575 if hasattr (kernel , 'app' ):
@@ -581,7 +581,8 @@ def enable_gui(gui, kernel=None):
581581
582582 loop = loop_map [gui ]
583583 if loop and kernel .eventloop is not None and kernel .eventloop is not loop :
584- raise RuntimeError ("Cannot activate multiple GUI eventloops" )
584+ msg = "Cannot activate multiple GUI eventloops"
585+ raise RuntimeError (msg )
585586 kernel .eventloop = loop
586587 # We set `eventloop`; the function the user chose is executed in `Kernel.enter_eventloop`, thus
587588 # any exceptions raised during the event loop will not be shown in the client.
0 commit comments