-
-
Notifications
You must be signed in to change notification settings - Fork 32k
More callables should be usable as Exception Group predicates #105730
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
Comments
Thank you @SlaushVunter for the report. We could make more callables work with split(), but not all of them because that would be ambiguous - an Exception subclass is callable but it is matched by type and not as a predicate. Also, this would be a feature request rather than a bug report because the documentation says function, not callable. This means that it can only be changed in version 3.13. That said, I don't think the code you provided above is a good motivating example for this. Iterating over leaf exceptions of an exception group like this gives you the leaf exceptions with truncated tracebacks (too see how to do this, look at the leaf_generator function in https://peps.python.org/pep-0654/#handling-exception-groups). I would probably just |
Thank you for the quick reply, and the quick fix! And sorry for my late answer. My example was the result of a simplification. In my original example I did not want to log the traceback for the matched leaf exceptions (communication errors), because they are not needed, the error message is enough. Anyway thank you for your suggestion also. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
If a bound method is used as the condition for BaseExceptionGroup.split the following exception is raised:
Consider the following example:
If we replace the bound method with a lambda (
lambda e: self._log_and_ignore_error(e)
) then no exception is raised.I think it would be useful to accept any callable here. I guess the code update would be simple too, just replace PyFunction_Check with PyCallable_Check in
Update the exception message to allow callables, and change the assert in
to call PyCallable_Check again.
Your environment
The c code snippets are from origin/main.
Linked PRs
The text was updated successfully, but these errors were encountered: