- In interactive mode with
sys.ps1
.
I guess I should elaborate a bit here. The proposed solution solves your problem – you would stop needing a workaround, and people would stop filing bug reports to your tool.
But what happens when someone else maintains a tool that does end up running Python in interactive mode, and gets bug reports and starts asking for a workaround? I wouldn’t be surprised if there are already tools doing that, and it feels like any solution needs to work for them just as well as for you.
If we had Django to do all over again, I agree that probably QuerySet.__repr__()
should be handled differently. But the current behavior is so long-standing and so baked in to people’s assumptions about how to teach and debug Django that I don’t think Django can make the change, now, to differentiate __str__()
(evaluates the query) and __repr__()
(doesn’t evaluate the query).
(though it might not even be usefully possible if starting over completely: the exact distinction between repr()
and str()
, and when to use each one, and why they exist as separate things, is not exactly accessible beginner-level Python knowledge, and I wouldn’t be surprised if a complete do-over of Django still ended up with both methods doing the same thing on QuerySet
)