1111from queue import Empty
1212
1313import zmq .asyncio
14- from traitlets import Any
15- from traitlets import Bool
16- from traitlets import Instance
17- from traitlets import Type
14+ from traitlets import Any , Bool , Instance , Type
1815
19- from .channelsabc import ChannelABC
20- from .channelsabc import HBChannelABC
16+ from jupyter_client .channels import major_protocol_version
17+ from jupyter_client .utils import ensure_async
18+
19+ from .channelsabc import ChannelABC , HBChannelABC
2120from .clientabc import KernelClientABC
2221from .connect import ConnectionFileMixin
2322from .session import Session
24- from jupyter_client .channels import major_protocol_version
25- from jupyter_client .utils import ensure_async
23+
2624
2725# some utilities to validate message structure, these might get moved elsewhere
2826# if they prove to have more generic utility
@@ -265,7 +263,7 @@ def _output_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
265263 elif msg_type in ("display_data" , "execute_result" ):
266264 sys .stdout .write (content ["data" ].get ("text/plain" , "" ))
267265 elif msg_type == "error" :
268- print ("\n " .join (content ["traceback" ]), file = sys . stderr )
266+ sys . stderr . write ("\n " .join (content ["traceback" ]))
269267
270268 def _output_hook_kernel (
271269 self ,
@@ -621,14 +619,14 @@ def execute(
621619
622620 # Create class for content/msg creation. Related to, but possibly
623621 # not in Session.
624- content = dict (
625- code = code ,
626- silent = silent ,
627- store_history = store_history ,
628- user_expressions = user_expressions ,
629- allow_stdin = allow_stdin ,
630- stop_on_error = stop_on_error ,
631- )
622+ content = {
623+ " code" : code ,
624+ " silent" : silent ,
625+ " store_history" : store_history ,
626+ " user_expressions" : user_expressions ,
627+ " allow_stdin" : allow_stdin ,
628+ " stop_on_error" : stop_on_error ,
629+ }
632630 msg = self .session .msg ("execute_request" , content )
633631 self .shell_channel .send (msg )
634632 return msg ["header" ]["msg_id" ]
@@ -651,7 +649,7 @@ def complete(self, code: str, cursor_pos: t.Optional[int] = None) -> str:
651649 """
652650 if cursor_pos is None :
653651 cursor_pos = len (code )
654- content = dict ( code = code , cursor_pos = cursor_pos )
652+ content = { " code" : code , " cursor_pos" : cursor_pos }
655653 msg = self .session .msg ("complete_request" , content )
656654 self .shell_channel .send (msg )
657655 return msg ["header" ]["msg_id" ]
@@ -678,11 +676,11 @@ def inspect(self, code: str, cursor_pos: t.Optional[int] = None, detail_level: i
678676 """
679677 if cursor_pos is None :
680678 cursor_pos = len (code )
681- content = dict (
682- code = code ,
683- cursor_pos = cursor_pos ,
684- detail_level = detail_level ,
685- )
679+ content = {
680+ " code" : code ,
681+ " cursor_pos" : cursor_pos ,
682+ " detail_level" : detail_level ,
683+ }
686684 msg = self .session .msg ("inspect_request" , content )
687685 self .shell_channel .send (msg )
688686 return msg ["header" ]["msg_id" ]
@@ -754,7 +752,7 @@ def comm_info(self, target_name: t.Optional[str] = None) -> str:
754752 if target_name is None :
755753 content = {}
756754 else :
757- content = dict ( target_name = target_name )
755+ content = { " target_name" : target_name }
758756 msg = self .session .msg ("comm_info_request" , content )
759757 self .shell_channel .send (msg )
760758 return msg ["header" ]["msg_id" ]
@@ -790,7 +788,7 @@ def input(self, string: str) -> None:
790788 -------
791789 The ID of the message sent.
792790 """
793- content = dict ( value = string )
791+ content = { " value" : string }
794792 msg = self .session .msg ("input_reply" , content )
795793 self .stdin_channel .send (msg )
796794
0 commit comments