-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Api callback exceptions #9063
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
Api callback exceptions #9063
Conversation
I also considered defaulting to using the printer, and explicitly passing |
I think defaulting to the printer is better (with an explicit None to disable it, or perhaps event just lambda exc: None which avoids the need for special casing). |
Notes from call:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I'm neutral WRT defaulting; maybe just a little in favor of it, as it simplifies things a bit.
a3e382c
to
461ba8e
Compare
doc/api/api_changes/2017-08_TAC.rst
Outdated
cb = CallbackRegistry(exception_handler=None) | ||
|
||
|
||
A function which take and ``Exception`` as it's only argument may also be passed :: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its
lib/matplotlib/cbook/__init__.py
Outdated
@@ -249,9 +249,12 @@ def __hash__(self): | |||
return self._hash | |||
|
|||
|
|||
def _excption_printer(exp): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo? (exception)
also I usually use "exc", not "exp", as variable name for an exception
lib/matplotlib/cbook/__init__.py
Outdated
@@ -365,6 +389,13 @@ def process(self, s, *args, **kwargs): | |||
proxy(*args, **kwargs) | |||
except ReferenceError: | |||
self._remove_proxy(proxy) | |||
# this does not capture KeyboardInterrupt, SystemExit, | |||
# and GeneratorExit | |||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the technically correct way to do this is to store weakref.refs rather than weakref.proxies, so that we can distinguish between failure in dereferencing the callback weakref.ref and failures raised from within the callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good enough for now, we are not doing the right thing in the case where the function we are proxying does not properly handle it's own weak-refs going away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok to leave this as is for now (we should just drop Py2 and use WeakMethods anyways :-))
461ba8e
to
0cbd53f
Compare
doc/api/api_changes/2017-08_TAC.rst
Outdated
|
||
A function which take and ``Exception`` as its only argument may also be passed :: | ||
|
||
def maybe_reraise(excp): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this def reraise_runtime_errors(exc): ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it reraises everything but RuntimeError
.
lib/matplotlib/cbook/__init__.py
Outdated
exception_handler : callable, optional | ||
If provided must have signature :: | ||
|
||
def handler(exception: Exception) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def handler(exc: Exception) -> None
(for consistency with, e.g. the default handler below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer some variables be renamed but that's really not so important.
hit 50% of @anntzer 's asks ;) |
Thanks! |
alternative to #7197
Still needs tests and doc