repr () not used in window displays (Issue #1661 continued) #1203
Replies: 2 comments
-
This is something that really should be tackled on the Python side of things, because it's a problem that affects all IDEs (and really anything that has to visualize Python data structures). This is not a trivial design issue, because such a hook needs to allow objects to coordinate - e.g. in your case you don't want to apply nesting limitations, but other collections might. OTOH if Python does it, it can be designed much more flexibly than our implementation - for example, instead of expecting the repr to return the value, it can supply a builder object with methods to append text, and to recursively invoke repr on a contained value; and the builder can then keep track of things like nesting level or number of elements rendered. The stdlib collections could then also implement it properly. @brettcannon, is that something that would be PEP-worthy? The gist is to have a form of |
Beta Was this translation helpful? Give feedback.
-
@int19h you could propose it on python-ideas and see if people are positive on the idea. |
Beta Was this translation helpful? Give feedback.
-
In safe_repr.py, ptvsd estimates whether repr (obj) might be too long to send to the IDE. In my code, I have a class derived from list, and if I have more than two levels of nesting, it is considered too long.
Please consider the following solution: If the obj being displayed has a method called 'safe_repr', then this is called directly. I put the following in my local copy of safe_repr.py:
def call(self, obj):
The name 'safe_repr' is something I made up. You might want to provide some other way to tell SafeRepr (obj) that repr (obj) is OK to use.
Environment data
Beta Was this translation helpful? Give feedback.
All reactions