New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a limit arguments for __repr__ #85555
Comments
Quoting Elizaveta Shashkova from EuroPython 2020 chat about how can we improve debug experience for users: I would like to have a lazy repr evaluation for the objects! Sometimes users have many really large objects, and when debugger is trying to show them in Variables View (=show their string representation) it can takes a lot of time. We do some tricks, but they not always work. It would be really-really cool to have parameter in repr, which defines max number of symbols we want to evaluate during repr for this object. What do people, would this optional str limit be a good thing? Does anyone has a better idea? |
Hi Bernat, have you looked into reprlib.repr()? It's an alternative implementation of repr() made for cases like this. You may be interested in this PR too: #20925 Alternatively, I think pprint.pformat() may be useful for your purpose too. |
Thanks Rémi, did not know about it. Played around with it, and is not entirely what we'd need here. That class still generates the long string repr, just truncates it afterwards. That is unless teh Repr implements custom formatting for the types, however the Repr would be the IDEs code, and that doesn't understand enough the user code to be able to tell what's a good short representation for it. This was the idea with adding it as a parameter to the repr function, that the user can customize/override the outcome depenending how many characters it has left to use up for repr. |
I suggest taking this to Python ideas. While there is a legitimate concern about large objects in a Variable View, the idea impacts long-standing core APIs. Accordingly, it needs to be thought through, become better specified, and be evaluated against alternatives. If the language impact is pervasive, it would likely need a PEP as well. Some questions immediately come to mind:
|
I don't know if this was ever taken to python-ideas, so I'll continue here. I don't think there is any chance we can override the Consequently the only way to do this would be to define a new API (strawman: Alternatively, you could lobby for specific improvements to pprint or reprlib (both of which seem to be halfway there). In particular it would seem that if we make one or the other extensible so that user code can register additional handlers for its own types. This is somewhat similar to defining a new dunder but as a feature request for either pprint or reprlib it is much easier to get this idea approved. I don't know exactly what your use case is, so please look at these two modules carefully and come back with a specific proposal. |
I think @Elizaveta239 would be able to describe better what she had in mind |
Hi @gvanrossum! Thank you for your explanation and for the suggestions! Looks like |
BernatGabor mannequin commentedJul 24, 2020
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: