Closed richardsheridan closed 1 month ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 99.63%. Comparing base (
3350c11
) to head (b4af483
).
Looks like that traceback cleanup trick only works on 3.11 later. Either we could find a different trick or only assert it on recent python versions!
Cc @clint-lawrence cause you made the original PR
Out of date branch so updated
The difference in editing exceptions that showed up in 3.11 is documented so I think we can just rely on it.
And to follow up on people interested in a nursery for background tasks, my test accidentally shows that you can just use the system nursery.
A really clean (IMO) implementation breaks certain features of InteractiveConsole
intended to enable customization in subclasses. So I made it final
to discourage people from trying and noted in comments which things won't work for future contributors to this class.
Not immediately obvious that raising the error in that branch causes error to be only printed and not close repl if I am reading the comment right.
Yes, I think I did a poor job of splitting up that comment. I'm going clarify that a bit and then someone can do a nice squash merge for us.
A follow up to #2972. These would have been review comments earlier if I knew the code was going to be (a) this simple and (b) in my wheelhouse!
I think
runcode
can just be:It's less code, less layers of onion unwrapping, and the more common
from_thread.run_sync
is more efficient (not that anyone would notice latency from two extra checkpoints at the REPL). That's the first commit.I also noticed one fragility, which is that KI works thanks to the thread task reentry feature combined with the fact that we inject
KeyboardInterrupt
into the main task. If we were to go the route of https://github.com/python-trio/trio/issues/733#issuecomment-629126671 and just cancel everything and transmute toKeyboardInterrupt
when the run finishes, the run would be cancelled. I put a test for this in the second commit.Finally, we can hide the threading code frames from the traceback, although I'm not sure about editing the global exception state like that. that's the last commit.