58
58
from ._version import kernel_protocol_version
59
59
from .iostream import OutStream
60
60
61
+ _AWAITABLE_MESSAGE : str = (
62
+ "For consistency across implementations, it is recommended that `{func_name}`"
63
+ " either be a coroutine function (`async def`) or return an awaitable object"
64
+ " (like an `asyncio.Future`). It might become a requirement in the future."
65
+ " Coroutine functions and awaitables have been supported since"
66
+ " ipykernel 6.0 (2021). {target} does not seem to return an awaitable"
67
+ )
68
+
61
69
62
70
def _accepts_parameters (meth , param_names ):
63
71
parameters = inspect .signature (meth ).parameters
@@ -745,6 +753,12 @@ async def execute_request(self, socket, ident, parent):
745
753
746
754
if inspect .isawaitable (reply_content ):
747
755
reply_content = await reply_content
756
+ else :
757
+ warnings .warn (
758
+ _AWAITABLE_MESSAGE .format (func_name = "do_execute" , target = self .do_execute ),
759
+ PendingDeprecationWarning ,
760
+ stacklevel = 1 ,
761
+ )
748
762
749
763
# Flush output before sending the reply.
750
764
if sys .stdout is not None :
@@ -805,6 +819,12 @@ async def complete_request(self, socket, ident, parent):
805
819
matches = self .do_complete (code , cursor_pos )
806
820
if inspect .isawaitable (matches ):
807
821
matches = await matches
822
+ else :
823
+ warnings .warn (
824
+ _AWAITABLE_MESSAGE .format (func_name = "do_complete" , target = self .do_complete ),
825
+ PendingDeprecationWarning ,
826
+ stacklevel = 1 ,
827
+ )
808
828
809
829
matches = json_clean (matches )
810
830
self .session .send (socket , "complete_reply" , matches , parent , ident )
@@ -833,6 +853,12 @@ async def inspect_request(self, socket, ident, parent):
833
853
)
834
854
if inspect .isawaitable (reply_content ):
835
855
reply_content = await reply_content
856
+ else :
857
+ warnings .warn (
858
+ _AWAITABLE_MESSAGE .format (func_name = "do_inspect" , target = self .do_inspect ),
859
+ PendingDeprecationWarning ,
860
+ stacklevel = 1 ,
861
+ )
836
862
837
863
# Before we send this object over, we scrub it for JSON usage
838
864
reply_content = json_clean (reply_content )
@@ -852,6 +878,12 @@ async def history_request(self, socket, ident, parent):
852
878
reply_content = self .do_history (** content )
853
879
if inspect .isawaitable (reply_content ):
854
880
reply_content = await reply_content
881
+ else :
882
+ warnings .warn (
883
+ _AWAITABLE_MESSAGE .format (func_name = "do_history" , target = self .do_history ),
884
+ PendingDeprecationWarning ,
885
+ stacklevel = 1 ,
886
+ )
855
887
856
888
reply_content = json_clean (reply_content )
857
889
msg = self .session .send (socket , "history_reply" , reply_content , parent , ident )
@@ -974,6 +1006,12 @@ async def shutdown_request(self, socket, ident, parent):
974
1006
content = self .do_shutdown (parent ["content" ]["restart" ])
975
1007
if inspect .isawaitable (content ):
976
1008
content = await content
1009
+ else :
1010
+ warnings .warn (
1011
+ _AWAITABLE_MESSAGE .format (func_name = "do_shutdown" , target = self .do_shutdown ),
1012
+ PendingDeprecationWarning ,
1013
+ stacklevel = 1 ,
1014
+ )
977
1015
self .session .send (socket , "shutdown_reply" , content , parent , ident = ident )
978
1016
# same content, but different msg_id for broadcasting on IOPub
979
1017
self ._shutdown_message = self .session .msg ("shutdown_reply" , content , parent )
@@ -998,6 +1036,12 @@ async def is_complete_request(self, socket, ident, parent):
998
1036
reply_content = self .do_is_complete (code )
999
1037
if inspect .isawaitable (reply_content ):
1000
1038
reply_content = await reply_content
1039
+ else :
1040
+ warnings .warn (
1041
+ _AWAITABLE_MESSAGE .format (func_name = "do_is_complete" , target = self .do_is_complete ),
1042
+ PendingDeprecationWarning ,
1043
+ stacklevel = 1 ,
1044
+ )
1001
1045
reply_content = json_clean (reply_content )
1002
1046
reply_msg = self .session .send (socket , "is_complete_reply" , reply_content , parent , ident )
1003
1047
self .log .debug ("%s" , reply_msg )
@@ -1014,6 +1058,14 @@ async def debug_request(self, socket, ident, parent):
1014
1058
reply_content = self .do_debug_request (content )
1015
1059
if inspect .isawaitable (reply_content ):
1016
1060
reply_content = await reply_content
1061
+ else :
1062
+ warnings .warn (
1063
+ _AWAITABLE_MESSAGE .format (
1064
+ func_name = "do_debug_request" , target = self .do_debug_request
1065
+ ),
1066
+ PendingDeprecationWarning ,
1067
+ stacklevel = 1 ,
1068
+ )
1017
1069
reply_content = json_clean (reply_content )
1018
1070
reply_msg = self .session .send (socket , "debug_reply" , reply_content , parent , ident )
1019
1071
self .log .debug ("%s" , reply_msg )
0 commit comments