On Sat, Jul 25, 2020 at 1:18 AM Gábor Bernát <jokerjoke...@gmail.com> wrote: > > Hello, I'd like to bring to your attention > https://bugs.python.org/issue41383. The core idea here is per Elizaveta > Shashkova: > > 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. > Maybe repr is not the best here, because that should be interpreter > meaningful, but instead the __str__ method that's better for this. Maybe we > could pass in an optional limit argument to these methods, so that the user > can decide what to print depending on how many characters he has left? >
I honestly don't think that either __repr__ or __str__ is appropriate for this. You need some sort of hook that has, potentially, a lot of debugger hooks in it. I would say it's best handled by some sort of multiple dispatch within the debugger itself; it can handle core data types (list/tuple, dict) and then provide hooks for custom types to register themselves with it. But one thing that would be kinda nice would be to have a way for a class to say "I'm like a dict, but with extra info". Consider defaultdict and Counter: >>> c = collections.defaultdict(list) >>> c[1].append("asdf") >>> c defaultdict(<class 'list'>, {1: ['asdf']}) >>> collections.Counter("Hello, world") Counter({'l': 3, 'o': 2, 'H': 1, 'e': 1, ',': 1, ' ': 1, 'w': 1, 'r': 1, 'd': 1}) Both of them include a dict-like repr in their reprs, and both of them would probably want to have the debugger display them in a dict-like way too. Maybe reprlib would be the place for something like this? ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SLBUWGKDYNZ5RXXVIDXH27XM4RKBCMDQ/ Code of Conduct: http://python.org/psf/codeofconduct/