Printing debug information in __repr__ only when a debugger has set a trace
#2091
+8
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due Diligence
Description
Python uses
__repr__and__str__to give textual information about objects. The intention is that__repr__gives output for developers and__str__gives output for users. In heat arrays, this means__repr__tells you, for each MPI rank, what kind of data is contained in the array, while__str__tells you the actual data.This is all well and good but the problem is when people are using heat interactively, in which case they get the
__repr__if they just print the array, but if they are users, they want to know the data and not the local shape.For example:
when doing something like this, you tend to want to know the contents of the array in both cases, i.e. the result of
__str__.This PR is not a very nice solution and I would be fine if we reject this, but I don't know a better way.
What this PR proposes is to return the normal
__str__output in__repr__, unless the interactive session is a debugging session. This is determined viasys.gettrace().Issue/s resolved: #2018
Changes proposed:
__repr__only if the interactive session is a debugging session