11
11
from queue import Empty
12
12
13
13
import 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
18
15
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
21
20
from .clientabc import KernelClientABC
22
21
from .connect import ConnectionFileMixin
23
22
from .session import Session
24
- from jupyter_client .channels import major_protocol_version
25
- from jupyter_client .utils import ensure_async
23
+
26
24
27
25
# some utilities to validate message structure, these might get moved elsewhere
28
26
# if they prove to have more generic utility
@@ -265,7 +263,7 @@ def _output_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
265
263
elif msg_type in ("display_data" , "execute_result" ):
266
264
sys .stdout .write (content ["data" ].get ("text/plain" , "" ))
267
265
elif msg_type == "error" :
268
- print ("\n " .join (content ["traceback" ]), file = sys . stderr )
266
+ sys . stderr . write ("\n " .join (content ["traceback" ]))
269
267
270
268
def _output_hook_kernel (
271
269
self ,
@@ -621,14 +619,14 @@ def execute(
621
619
622
620
# Create class for content/msg creation. Related to, but possibly
623
621
# 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
+ }
632
630
msg = self .session .msg ("execute_request" , content )
633
631
self .shell_channel .send (msg )
634
632
return msg ["header" ]["msg_id" ]
@@ -651,7 +649,7 @@ def complete(self, code: str, cursor_pos: t.Optional[int] = None) -> str:
651
649
"""
652
650
if cursor_pos is None :
653
651
cursor_pos = len (code )
654
- content = dict ( code = code , cursor_pos = cursor_pos )
652
+ content = { " code" : code , " cursor_pos" : cursor_pos }
655
653
msg = self .session .msg ("complete_request" , content )
656
654
self .shell_channel .send (msg )
657
655
return msg ["header" ]["msg_id" ]
@@ -678,11 +676,11 @@ def inspect(self, code: str, cursor_pos: t.Optional[int] = None, detail_level: i
678
676
"""
679
677
if cursor_pos is None :
680
678
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
+ }
686
684
msg = self .session .msg ("inspect_request" , content )
687
685
self .shell_channel .send (msg )
688
686
return msg ["header" ]["msg_id" ]
@@ -754,7 +752,7 @@ def comm_info(self, target_name: t.Optional[str] = None) -> str:
754
752
if target_name is None :
755
753
content = {}
756
754
else :
757
- content = dict ( target_name = target_name )
755
+ content = { " target_name" : target_name }
758
756
msg = self .session .msg ("comm_info_request" , content )
759
757
self .shell_channel .send (msg )
760
758
return msg ["header" ]["msg_id" ]
@@ -790,7 +788,7 @@ def input(self, string: str) -> None:
790
788
-------
791
789
The ID of the message sent.
792
790
"""
793
- content = dict ( value = string )
791
+ content = { " value" : string }
794
792
msg = self .session .msg ("input_reply" , content )
795
793
self .stdin_channel .send (msg )
796
794
0 commit comments