MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / internal_evaluate_expression_json

Function internal_evaluate_expression_json

_pydevd_bundle/pydevd_comm.py:1174–1289  ·  view source on GitHub ↗

:param EvaluateRequest request:

(py_db, request, thread_id)

Source from the content-addressed store, hash-verified

1172
1173
1174def internal_evaluate_expression_json(py_db, request, thread_id):
1175 """
1176 :param EvaluateRequest request:
1177 """
1178 global _global_frame
1179 # : :type arguments: EvaluateArguments
1180
1181 arguments = request.arguments
1182 expression = arguments.expression
1183 frame_id = arguments.frameId
1184 context = arguments.context
1185 fmt = arguments.format
1186 if hasattr(fmt, "to_dict"):
1187 fmt = fmt.to_dict()
1188
1189 ctx = NULL
1190 if context == "repl":
1191 if not py_db.is_output_redirected:
1192 ctx = pydevd_io.redirect_stream_to_pydb_io_messages_context()
1193 else:
1194 # If we're not in a repl (watch, hover, ...) don't show warnings.
1195 ctx = filter_all_warnings()
1196
1197 with ctx:
1198 try_exec = False
1199 if frame_id is None:
1200 if _global_frame is None:
1201 # Lazily create a frame to be used for evaluation with no frame id.
1202
1203 def __create_frame():
1204 yield sys._getframe()
1205
1206 _global_frame = next(__create_frame())
1207
1208 frame = _global_frame
1209 try_exec = True # Always exec in this case
1210 eval_result = None
1211 else:
1212 frame = py_db.find_frame(thread_id, frame_id)
1213
1214 eval_result = pydevd_vars.evaluate_expression(py_db, frame, expression, is_exec=False)
1215 is_error = isinstance_checked(eval_result, ExceptionOnEvaluate)
1216 if is_error:
1217 if context == "hover": # In a hover it doesn't make sense to do an exec.
1218 _evaluate_response(py_db, request, result="", error_message="Exception occurred during evaluation.")
1219 return
1220 elif context == "watch":
1221 # If it's a watch, don't show it as an exception object, rather, format
1222 # it and show it as a string (with success=False).
1223 msg = "%s: %s" % (
1224 eval_result.result.__class__.__name__,
1225 eval_result.result,
1226 )
1227 _evaluate_response(py_db, request, result=msg, error_message=msg)
1228 return
1229 else:
1230 # We only try the exec if the failure we had was due to not being able
1231 # to evaluate the expression.

Callers

nothing calls this directly

Calls 13

filter_all_warningsFunction · 0.90
isinstance_checkedFunction · 0.90
NetCommandClass · 0.90
__create_frameFunction · 0.85
_evaluate_responseFunction · 0.85
get_frame_trackerMethod · 0.80
obtain_as_variableMethod · 0.80
get_var_dataMethod · 0.80
to_dictMethod · 0.45
find_frameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected