Skip to content

Commit 24ccced

Browse files
committed
Printing debug information only when debugger has set a trace
1 parent a2994ab commit 24ccced

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

heat/core/dndarray.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import math
6+
import sys
67
import numpy as np
78
import torch
89
import warnings
@@ -1245,11 +1246,14 @@ def _repr_pretty_(self, p, cycle):
12451246
else:
12461247
p.text(printing.__str__(self))
12471248

1248-
def __repr__(self) -> str:
1249+
def __repr__(self, force_debug_output=False) -> str:
12491250
"""
12501251
Returns a printable representation of the passed DNDarray, targeting developers.
12511252
"""
1252-
return printing.__repr__(self)
1253+
if sys.gettrace() is None and not force_debug_output: # Running without debugger
1254+
return printing.__str__(self)
1255+
else:
1256+
return printing.__repr__(self)
12531257

12541258
def ravel(self):
12551259
"""

heat/core/tests/test_printing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,12 @@ def test_split_2_above_threshold(self):
432432

433433
def test___repr__(self):
434434
a = ht.array([1, 2, 3, 4])
435-
r = a.__repr__()
435+
r = a.__repr__(force_debug_output=True)
436436
self.assertEqual(
437437
r,
438438
f"<DNDarray(MPI-rank: {a.comm.rank}, Shape: {a.shape}, Split: {a.split}, Local Shape: {a.lshape}, Device: {a.device}, Dtype: {a.dtype.__name__})>",
439439
)
440+
self.assertEqual(a.__repr__(), a.__str__())
440441

441442

442443
class TestPrintingGPU(TestCase):

0 commit comments

Comments
 (0)