57
57
from ._version import kernel_protocol_version
58
58
from .iostream import OutStream
59
59
60
+ _AWAITABLE_MESSAGE : str = (
61
+ "For consistency across implementations, it is recommended that `{func_name}`"
62
+ " either be a coroutine function (`async def`) or return an awaitable object"
63
+ " (like a Future). It might become a requirement in the future."
64
+ " Coroutine functions and awaitables have been supported since"
65
+ " ipykernel 6.0 (2021)."
66
+ )
67
+
60
68
61
69
def _accepts_parameters (meth , param_names ):
62
70
parameters = inspect .signature (meth ).parameters
@@ -742,6 +750,12 @@ async def execute_request(self, socket, ident, parent):
742
750
743
751
if inspect .isawaitable (reply_content ):
744
752
reply_content = await reply_content
753
+ else :
754
+ warnings .warn (
755
+ _AWAITABLE_MESSAGE .format (func_name = "execute_request" ),
756
+ PendingDeprecationWarning ,
757
+ stacklevel = 1 ,
758
+ )
745
759
746
760
# Flush output before sending the reply.
747
761
if sys .stdout is not None :
@@ -802,6 +816,12 @@ async def complete_request(self, socket, ident, parent):
802
816
matches = self .do_complete (code , cursor_pos )
803
817
if inspect .isawaitable (matches ):
804
818
matches = await matches
819
+ else :
820
+ warnings .warn (
821
+ _AWAITABLE_MESSAGE .format (func_name = "do_complete" ),
822
+ PendingDeprecationWarning ,
823
+ stacklevel = 1 ,
824
+ )
805
825
806
826
matches = json_clean (matches )
807
827
self .session .send (socket , "complete_reply" , matches , parent , ident )
@@ -830,6 +850,12 @@ async def inspect_request(self, socket, ident, parent):
830
850
)
831
851
if inspect .isawaitable (reply_content ):
832
852
reply_content = await reply_content
853
+ else :
854
+ warnings .warn (
855
+ _AWAITABLE_MESSAGE .format (func_name = "do_inspect" ),
856
+ PendingDeprecationWarning ,
857
+ stacklevel = 1 ,
858
+ )
833
859
834
860
# Before we send this object over, we scrub it for JSON usage
835
861
reply_content = json_clean (reply_content )
@@ -849,6 +875,12 @@ async def history_request(self, socket, ident, parent):
849
875
reply_content = self .do_history (** content )
850
876
if inspect .isawaitable (reply_content ):
851
877
reply_content = await reply_content
878
+ else :
879
+ warnings .warn (
880
+ _AWAITABLE_MESSAGE .format (func_name = "do_history" ),
881
+ PendingDeprecationWarning ,
882
+ stacklevel = 1 ,
883
+ )
852
884
853
885
reply_content = json_clean (reply_content )
854
886
msg = self .session .send (socket , "history_reply" , reply_content , parent , ident )
@@ -966,6 +998,12 @@ async def shutdown_request(self, socket, ident, parent):
966
998
content = self .do_shutdown (parent ["content" ]["restart" ])
967
999
if inspect .isawaitable (content ):
968
1000
content = await content
1001
+ else :
1002
+ warnings .warn (
1003
+ _AWAITABLE_MESSAGE .format (func_name = "do_shutdown" ),
1004
+ PendingDeprecationWarning ,
1005
+ stacklevel = 1 ,
1006
+ )
969
1007
self .session .send (socket , "shutdown_reply" , content , parent , ident = ident )
970
1008
# same content, but different msg_id for broadcasting on IOPub
971
1009
self ._shutdown_message = self .session .msg ("shutdown_reply" , content , parent )
@@ -990,6 +1028,12 @@ async def is_complete_request(self, socket, ident, parent):
990
1028
reply_content = self .do_is_complete (code )
991
1029
if inspect .isawaitable (reply_content ):
992
1030
reply_content = await reply_content
1031
+ else :
1032
+ warnings .warn (
1033
+ _AWAITABLE_MESSAGE .format (func_name = "do_is_complete" ),
1034
+ PendingDeprecationWarning ,
1035
+ stacklevel = 1 ,
1036
+ )
993
1037
reply_content = json_clean (reply_content )
994
1038
reply_msg = self .session .send (socket , "is_complete_reply" , reply_content , parent , ident )
995
1039
self .log .debug ("%s" , reply_msg )
@@ -1006,6 +1050,12 @@ async def debug_request(self, socket, ident, parent):
1006
1050
reply_content = self .do_debug_request (content )
1007
1051
if inspect .isawaitable (reply_content ):
1008
1052
reply_content = await reply_content
1053
+ else :
1054
+ warnings .warn (
1055
+ _AWAITABLE_MESSAGE .format (func_name = "do_debug_request" ),
1056
+ PendingDeprecationWarning ,
1057
+ stacklevel = 1 ,
1058
+ )
1009
1059
reply_content = json_clean (reply_content )
1010
1060
reply_msg = self .session .send (socket , "debug_reply" , reply_content , parent , ident )
1011
1061
self .log .debug ("%s" , reply_msg )
0 commit comments