From c008e8a220698e2b457d4d3d624d8d901a88dc99 Mon Sep 17 00:00:00 2001 From: Ricky Zhu Date: Fri, 30 Aug 2024 10:07:14 +0800 Subject: [PATCH] to display length/shape Displays the size of an Sized variable before displaying its value, such as np.ndrray, torch.Tensor. Can benefit ML/AI programming, as well as other programming that works heavily on large collections. ddressing #1525, #1191, #4244, etc (issues of debugpy). --- .../types/pydevd_plugin_sized_str.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pydevd_plugins/extensions/types/pydevd_plugin_sized_str.py diff --git a/pydevd_plugins/extensions/types/pydevd_plugin_sized_str.py b/pydevd_plugins/extensions/types/pydevd_plugin_sized_str.py new file mode 100644 index 00000000..80daf17e --- /dev/null +++ b/pydevd_plugins/extensions/types/pydevd_plugin_sized_str.py @@ -0,0 +1,20 @@ +from _pydevd_bundle.pydevd_extension_api import StrPresentationProvider +from .pydevd_helpers import find_mod_attr + + +class SizedShapeStr: + '''Displays the size of a Sized object before displaying its value. + ''' + def can_provide(self, type_object, type_name): + sized_obj = find_mod_attr('collections.abc', 'Sized') + return sized_obj is not None and issubclass(type_object, sized_obj) + + def get_str(self, val): + if hasattr(val, 'shape'): + return f'shape: {val.shape}, value: {val}' + return f'len: {len(val)}, value: {val}' + +import sys + +if not sys.platform.startswith("java"): + StrPresentationProvider.register(SizedShapeStr)