@@ -96,12 +96,17 @@ namespace xpyt
96
96
97
97
// Add get_ipython to global namespace
98
98
py::globals ()[" get_ipython" ] = get_kernel_module ().attr (" get_ipython" );
99
-
99
+
100
100
// Initializes get_ipython result
101
101
get_kernel_module ().attr (" get_ipython" )();
102
102
103
103
m_has_ipython = get_kernel_module ().attr (" has_ipython" ).cast <bool >();
104
104
// m_has_ipython = true;
105
+
106
+ // Initialize cached inputs
107
+ py::globals ()[" _i" ] = " " ;
108
+ py::globals ()[" _ii" ] = " " ;
109
+ py::globals ()[" _iii" ] = " " ;
105
110
}
106
111
107
112
nl::json interpreter::execute_request_impl (int execution_count,
@@ -129,26 +134,26 @@ namespace xpyt
129
134
// - either we reimplement the parsing logic in xeus-python
130
135
// - or this logic is extracted from IPython into a dedicated package, that becomes
131
136
// a dependency of both xeus-python and IPython.
132
- if (code.size () >= 2 && code[0 ] == ' ?' )
133
- {
134
- std::string result = formatted_docstring (code);
135
- if (result.empty ())
136
- {
137
- result = " Object " + code.substr (1 ) + " not found." ;
138
- }
139
-
140
- kernel_res[" status" ] = " ok" ;
141
- kernel_res[" payload" ] = nl::json::array ();
142
- kernel_res[" payload" ][0 ] = nl::json::object ({
143
- {" data" , {
144
- {" text/plain" , result}
145
- }},
146
- {" source" , " page" },
147
- {" start" , 0 }
148
- });
149
- kernel_res[" user_expressions" ] = nl::json::object ();
150
-
151
- return kernel_res;
137
+ if (code.size () >= 2 && code[0 ] == ' ?' )
138
+ {
139
+ std::string result = formatted_docstring (code);
140
+ if (result.empty ())
141
+ {
142
+ result = " Object " + code.substr (1 ) + " not found." ;
143
+ }
144
+
145
+ kernel_res[" status" ] = " ok" ;
146
+ kernel_res[" payload" ] = nl::json::array ();
147
+ kernel_res[" payload" ][0 ] = nl::json::object ({
148
+ {" data" , {
149
+ {" text/plain" , result}
150
+ }},
151
+ {" source" , " page" },
152
+ {" start" , 0 }
153
+ });
154
+ kernel_res[" user_expressions" ] = nl::json::object ();
155
+
156
+ return kernel_res;
152
157
}
153
158
code_copy = code;
154
159
}
@@ -237,6 +242,11 @@ namespace xpyt
237
242
kernel_res[" traceback" ] = error.m_traceback ;
238
243
}
239
244
245
+ // Cache inputs
246
+ py::globals ()[" _iii" ] = py::globals ()[" _ii" ];
247
+ py::globals ()[" _ii" ] = py::globals ()[" _i" ];
248
+ py::globals ()[" _i" ] = code;
249
+
240
250
return kernel_res;
241
251
}
242
252
0 commit comments