@@ -118,7 +118,7 @@ def __init__(self, **kwargs):
118118 )
119119
120120 # Initialize the InteractiveShell subclass
121- self .shell = self .shell_class .instance (
121+ self .shell = self .shell_class .instance ( # type:ignore[attr-defined]
122122 parent = self ,
123123 profile_dir = self .profile_dir ,
124124 user_module = self .user_module ,
@@ -206,7 +206,8 @@ def dispatch_debugpy(self, msg):
206206
207207 @property
208208 def banner (self ):
209- return self .shell .banner
209+ if self .shell :
210+ return self .shell .banner
210211
211212 async def poll_stopped_queue (self ):
212213 """Poll the stopped queue."""
@@ -215,7 +216,8 @@ async def poll_stopped_queue(self):
215216
216217 def start (self ):
217218 """Start the kernel."""
218- self .shell .exit_now = False
219+ if self .shell :
220+ self .shell .exit_now = False
219221 if self .debugpy_stream is None :
220222 self .log .warning ("debugpy_stream undefined, debugging will not be enabled" )
221223 else :
@@ -231,7 +233,7 @@ def set_parent(self, ident, parent, channel="shell"):
231233 about the parent message.
232234 """
233235 super ().set_parent (ident , parent , channel )
234- if channel == "shell" :
236+ if channel == "shell" and self . shell :
235237 self .shell .set_parent (parent )
236238
237239 def init_metadata (self , parent ):
@@ -284,7 +286,8 @@ def _restore_input(self):
284286
285287 @property
286288 def execution_count (self ):
287- return self .shell .execution_count
289+ if self .shell :
290+ return self .shell .execution_count
288291
289292 @execution_count .setter
290293 def execution_count (self , value ):
@@ -348,6 +351,7 @@ async def do_execute(
348351 ):
349352 """Handle code execution."""
350353 shell = self .shell # we'll need this a lot here
354+ assert shell is not None
351355
352356 self ._forward_input (allow_stdin )
353357
@@ -371,7 +375,7 @@ async def run_cell(*args, **kwargs):
371375 # not just asyncio
372376 preprocessing_exc_tuple = None
373377 try :
374- transformed_cell = self . shell .transform_cell (code )
378+ transformed_cell = shell .transform_cell (code )
375379 except Exception :
376380 transformed_cell = code
377381 preprocessing_exc_tuple = sys .exc_info ()
@@ -488,6 +492,7 @@ def do_complete(self, code, cursor_pos):
488492 cursor_pos = len (code )
489493 line , offset = line_at_cursor (code , cursor_pos )
490494 line_cursor = cursor_pos - offset
495+ assert self .shell is not None
491496 txt , matches = self .shell .complete ("" , line , line_cursor )
492497 return {
493498 "matches" : matches ,
@@ -509,6 +514,7 @@ def _experimental_do_complete(self, code, cursor_pos):
509514 if cursor_pos is None :
510515 cursor_pos = len (code )
511516 with _provisionalcompleter ():
517+ assert self .shell is not None
512518 raw_completions = self .shell .Completer .completions (code , cursor_pos )
513519 completions = list (_rectify_completions (code , raw_completions ))
514520
@@ -548,6 +554,7 @@ def do_inspect(self, code, cursor_pos, detail_level=0, omit_sections=()):
548554 reply_content : t .Dict [str , t .Any ] = {"status" : "ok" }
549555 reply_content ["data" ] = {}
550556 reply_content ["metadata" ] = {}
557+ assert self .shell is not None
551558 try :
552559 if release .version_info >= (8 ,):
553560 # `omit_sections` keyword will be available in IPython 8, see
@@ -581,6 +588,7 @@ def do_history(
581588 unique = False ,
582589 ):
583590 """Handle code history."""
591+ assert self .shell is not None
584592 if hist_access_type == "tail" :
585593 hist = self .shell .history_manager .get_tail (
586594 n , raw = raw , output = output , include_latest = True
@@ -605,14 +613,16 @@ def do_history(
605613
606614 def do_shutdown (self , restart ):
607615 """Handle kernel shutdown."""
608- self .shell .exit_now = True
616+ if self .shell :
617+ self .shell .exit_now = True
609618 return dict (status = "ok" , restart = restart )
610619
611620 def do_is_complete (self , code ):
612621 """Handle an is_complete request."""
613622 transformer_manager = getattr (self .shell , "input_transformer_manager" , None )
614623 if transformer_manager is None :
615624 # input_splitter attribute is deprecated
625+ assert self .shell is not None
616626 transformer_manager = self .shell .input_splitter
617627 status , indent_spaces = transformer_manager .check_complete (code )
618628 r = {"status" : status }
@@ -628,6 +638,7 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
628638 from .serialize import serialize_object , unpack_apply_message
629639
630640 shell = self .shell
641+ assert shell is not None
631642 try :
632643 working = shell .user_ns
633644
@@ -652,6 +663,7 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
652663 for key in ns :
653664 working .pop (key )
654665
666+ assert self .session is not None
655667 result_buf = serialize_object (
656668 result ,
657669 buffer_threshold = self .session .buffer_threshold ,
@@ -686,7 +698,8 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
686698
687699 def do_clear (self ):
688700 """Clear the kernel."""
689- self .shell .reset (False )
701+ if self .shell :
702+ self .shell .reset (False )
690703 return dict (status = "ok" )
691704
692705
0 commit comments