-
Notifications
You must be signed in to change notification settings - Fork 68
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
Pretty print bot exceptions #846
Comments
while I agree that it would be nice to print the colors starting from Python 3.13, I am not convinced about using |
I wouldn’t call it ‘leaving the exceptions untouched’, given that we have to manually opt in for the Python 3.13 colours, but that’s also not the point of course. If it weren’t for the local variables, I would also say that Python does it good enough. My colour argument is mostly about finding the exception easily beneath long lines of logging. (And if this is still a problem with Python 3.13 style errors then there are other ways to solve this, too.) But having the local variables there could be a real advantage and timesaver. If you have some error in the 200th round, do you really want to litter your code with print statements, run it again and then wait 2 minutes for it to print it all and raise the exception again? (Obviously, this approach may still be needed, but perhaps not in all situations then.) (Ignoring the debugger here because I think it is a different thing and also not great to use without a gui.) |
ok, so maybe we need some more compelling examples? The screenshot you posted above does not even show that The debugger is not great to use, but more or less perfect for exactly this use case: print things in the local name space. We want to teach people the concept of the debugger, that is why we have a demo for a debuggable bot. |
It shows The problem with the debugger is that you have to engage it manually. What this context tells you is when you need to activate it. Without context, you are entering the debugger in every step round 1 and have to press |
Yes, this is a good idea, that we should address independently of the discussion about rich or not rich. It is not going to be so easy though, because just printing everything in bot is going to mess up the terminal even more, think of
sure, agreed. That is why the example above is not a good example. It does not tell you that the problem occurs at round 4. |
When we encounter an exception in the move function, we catch it in
team.py
and then manually print it withtraceback.print_exc()
. Modern Python versions do this much nicer with colour so, at the very least, we should change this line to:This will also make the exception easier to see in the terminal (assuming that a typical bot implementation is going to print hundreds of lines of black and white noise).
We could also opt for using
rich
here, which would be even fancier. It also comes with a neat addition in form of theshow_locals
flag that will list all local variables with their current values (super helpful, I’d say!):Unfortunately, we would only need this feature one frame above the current location; by default this will also print all variables that are currently defined in the
Team.get_move
function itself, which does make things rather confusing.It seems to be possible to exclude things but excluding the whole of Pelita might also not be a good idea: https://rich.readthedocs.io/en/stable/traceback.html#suppressing-frames
The text was updated successfully, but these errors were encountered: