-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
MultiError.catch should take an exception type, like except: does #408
Comments
For the newer version of catch, if we have with MultiError.catch(RuntimeError, handler):
... Does it means that we want the MultiError filter out the If so, what if we want to keep the behavior default? (just filter out the May be just pass with MultiError.catch(None, handler):
... |
@WindSoilder the idea is that with MultiError.catch(RuntimeError, handler):
... body ... is a substitute for try:
... body ...
except RuntimeError as exc:
handler(exc) The work the same except the first one handles When you talk about filtering |
@njsmith Thanks for your comment! It makes me more clear about this. But there is something still confuse me, take the code as example: with MultiError.catch(Cancelled, handler):
... body ... According to your description, when handler is called, it's argument type( I have take a look at Maybe this question is too foolish, but it still confuse me...I still don't understand the value of add an exception type to |
With the current With the "MultiError v2" proposal (#611), this changes slightly, and the exception type becomes more important. This proposal isn't implemented yet. But here, the idea is |
I haven't found catch() to be useful, and this improvement wouldn't help. The problem with the catch API is that the handler can only see one exception at a time. So far I've needed to see all exceptions to decide the desired filtering. Scenario: I want to defer any exceptions raised by my async API to Cancelled if they are raised simultaneously (e.g. if move_on_after expires I'm fine dropping any API exceptions). So if MultiError contains Cancelled, then filter my API's exceptions. It can't be done with catch(). |
@belm0 Interesting... are you up for writing a longer description of what you're trying to do in the v2 thread, #611? That's where the main design discussions have been happening for the |
Closing this because |
In regular Python, a catch-all exception handler looks like:
In Trio we need to handle
MultiError
s, which might contain a mix of exceptions we want to catch and ones we don't, etc. So you have to useMultiError.catch
, and the above becomes:This is pointlessly cumbersome. We should make it look like this:
The text was updated successfully, but these errors were encountered: