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

Function get_variable_details

_pydevd_bundle/pydevd_xml.py:320–392  ·  view source on GitHub ↗

:param context: This is the context in which the variable is being requested. Valid values: "watch", "repl", "hover", "clipboard"

(val, evaluate_full_value=True, to_string=None, context: Optional[str] = None)

Source from the content-addressed store, hash-verified

318
319
320def get_variable_details(val, evaluate_full_value=True, to_string=None, context: Optional[str] = None):
321 """
322 :param context:
323 This is the context in which the variable is being requested. Valid values:
324 "watch",
325 "repl",
326 "hover",
327 "clipboard"
328 """
329 try:
330 # This should be faster than isinstance (but we have to protect against not having a '__class__' attribute).
331 is_exception_on_eval = val.__class__ == ExceptionOnEvaluate
332 except:
333 is_exception_on_eval = False
334
335 if is_exception_on_eval:
336 v = val.result
337 else:
338 v = val
339
340 _type, type_name, resolver = get_type(v)
341 type_qualifier = getattr(_type, "__module__", "")
342 if not evaluate_full_value:
343 value = DEFAULT_VALUE
344 else:
345 try:
346 str_from_provider = _str_from_providers(v, _type, type_name, context)
347 if str_from_provider is not None:
348 value = str_from_provider
349
350 elif to_string is not None:
351 value = to_string(v)
352
353 elif hasattr_checked(v, "__class__"):
354 if v.__class__ == frame_type:
355 value = pydevd_resolver.frameResolver.get_frame_name(v)
356
357 elif v.__class__ in (list, tuple):
358 if len(v) > 300:
359 value = "%s: %s" % (str(v.__class__), "<Too big to print. Len: %s>" % (len(v),))
360 else:
361 value = "%s: %s" % (str(v.__class__), v)
362 else:
363 try:
364 cName = str(v.__class__)
365 if cName.find(".") != -1:
366 cName = cName.split(".")[-1]
367
368 elif cName.find("'") != -1: # does not have '.' (could be something like <type 'int'>)
369 cName = cName[cName.index("'") + 1 :]
370
371 if cName.endswith("'>"):
372 cName = cName[:-2]
373 except:
374 cName = str(v.__class__)
375
376 value = "%s: %s" % (cName, v)
377 else:

Callers 2

get_var_dataMethod · 0.90
var_to_xmlFunction · 0.85

Calls 5

hasattr_checkedFunction · 0.90
to_stringFunction · 0.85
get_frame_nameMethod · 0.80
findMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected