@@ -118,7 +118,7 @@ def __init__(self, **kwargs):
118
118
)
119
119
120
120
# Initialize the InteractiveShell subclass
121
- self .shell = self .shell_class .instance (
121
+ self .shell = self .shell_class .instance ( # type:ignore[attr-defined]
122
122
parent = self ,
123
123
profile_dir = self .profile_dir ,
124
124
user_module = self .user_module ,
@@ -206,7 +206,8 @@ def dispatch_debugpy(self, msg):
206
206
207
207
@property
208
208
def banner (self ):
209
- return self .shell .banner
209
+ if self .shell :
210
+ return self .shell .banner
210
211
211
212
async def poll_stopped_queue (self ):
212
213
"""Poll the stopped queue."""
@@ -215,7 +216,8 @@ async def poll_stopped_queue(self):
215
216
216
217
def start (self ):
217
218
"""Start the kernel."""
218
- self .shell .exit_now = False
219
+ if self .shell :
220
+ self .shell .exit_now = False
219
221
if self .debugpy_stream is None :
220
222
self .log .warning ("debugpy_stream undefined, debugging will not be enabled" )
221
223
else :
@@ -231,7 +233,7 @@ def set_parent(self, ident, parent, channel="shell"):
231
233
about the parent message.
232
234
"""
233
235
super ().set_parent (ident , parent , channel )
234
- if channel == "shell" :
236
+ if channel == "shell" and self . shell :
235
237
self .shell .set_parent (parent )
236
238
237
239
def init_metadata (self , parent ):
@@ -284,7 +286,8 @@ def _restore_input(self):
284
286
285
287
@property
286
288
def execution_count (self ):
287
- return self .shell .execution_count
289
+ if self .shell :
290
+ return self .shell .execution_count
288
291
289
292
@execution_count .setter
290
293
def execution_count (self , value ):
@@ -348,6 +351,7 @@ async def do_execute(
348
351
):
349
352
"""Handle code execution."""
350
353
shell = self .shell # we'll need this a lot here
354
+ assert shell is not None
351
355
352
356
self ._forward_input (allow_stdin )
353
357
@@ -371,7 +375,7 @@ async def run_cell(*args, **kwargs):
371
375
# not just asyncio
372
376
preprocessing_exc_tuple = None
373
377
try :
374
- transformed_cell = self . shell .transform_cell (code )
378
+ transformed_cell = shell .transform_cell (code )
375
379
except Exception :
376
380
transformed_cell = code
377
381
preprocessing_exc_tuple = sys .exc_info ()
@@ -488,6 +492,7 @@ def do_complete(self, code, cursor_pos):
488
492
cursor_pos = len (code )
489
493
line , offset = line_at_cursor (code , cursor_pos )
490
494
line_cursor = cursor_pos - offset
495
+ assert self .shell is not None
491
496
txt , matches = self .shell .complete ("" , line , line_cursor )
492
497
return {
493
498
"matches" : matches ,
@@ -509,6 +514,7 @@ def _experimental_do_complete(self, code, cursor_pos):
509
514
if cursor_pos is None :
510
515
cursor_pos = len (code )
511
516
with _provisionalcompleter ():
517
+ assert self .shell is not None
512
518
raw_completions = self .shell .Completer .completions (code , cursor_pos )
513
519
completions = list (_rectify_completions (code , raw_completions ))
514
520
@@ -548,6 +554,7 @@ def do_inspect(self, code, cursor_pos, detail_level=0, omit_sections=()):
548
554
reply_content : t .Dict [str , t .Any ] = {"status" : "ok" }
549
555
reply_content ["data" ] = {}
550
556
reply_content ["metadata" ] = {}
557
+ assert self .shell is not None
551
558
try :
552
559
if release .version_info >= (8 ,):
553
560
# `omit_sections` keyword will be available in IPython 8, see
@@ -581,6 +588,7 @@ def do_history(
581
588
unique = False ,
582
589
):
583
590
"""Handle code history."""
591
+ assert self .shell is not None
584
592
if hist_access_type == "tail" :
585
593
hist = self .shell .history_manager .get_tail (
586
594
n , raw = raw , output = output , include_latest = True
@@ -605,14 +613,16 @@ def do_history(
605
613
606
614
def do_shutdown (self , restart ):
607
615
"""Handle kernel shutdown."""
608
- self .shell .exit_now = True
616
+ if self .shell :
617
+ self .shell .exit_now = True
609
618
return dict (status = "ok" , restart = restart )
610
619
611
620
def do_is_complete (self , code ):
612
621
"""Handle an is_complete request."""
613
622
transformer_manager = getattr (self .shell , "input_transformer_manager" , None )
614
623
if transformer_manager is None :
615
624
# input_splitter attribute is deprecated
625
+ assert self .shell is not None
616
626
transformer_manager = self .shell .input_splitter
617
627
status , indent_spaces = transformer_manager .check_complete (code )
618
628
r = {"status" : status }
@@ -628,6 +638,7 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
628
638
from .serialize import serialize_object , unpack_apply_message
629
639
630
640
shell = self .shell
641
+ assert shell is not None
631
642
try :
632
643
working = shell .user_ns
633
644
@@ -652,6 +663,7 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
652
663
for key in ns :
653
664
working .pop (key )
654
665
666
+ assert self .session is not None
655
667
result_buf = serialize_object (
656
668
result ,
657
669
buffer_threshold = self .session .buffer_threshold ,
@@ -686,7 +698,8 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
686
698
687
699
def do_clear (self ):
688
700
"""Clear the kernel."""
689
- self .shell .reset (False )
701
+ if self .shell :
702
+ self .shell .reset (False )
690
703
return dict (status = "ok" )
691
704
692
705
0 commit comments