Skip to content

Require calling a _BoundMethodProxy to get the underlying callable. #9084

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

Merged
merged 1 commit into from
Jul 23, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Aug 24, 2017

Code that used to call _proxy(...) now needs to call _proxy()(...).

Instead of catching a ReferenceError, that could be either raised by a
failure to dereference the proxy, or by the underlying callable, one can
now check that _proxy() does not return None (to distinguish between
the two cases).

This is the same design as the stdlib's WeakMethod.

See #9063 (comment).

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Aug 27, 2017
@anntzer anntzer force-pushed the boundmethodproxy-like-weakmethod branch from bef9d16 to 28fd2d7 Compare February 15, 2018 10:39
@anntzer
Copy link
Contributor Author

anntzer commented Feb 15, 2018

rewritten to use weakref.WeakMethod directly

edit: needs some more work.

@anntzer anntzer modified the milestones: needs sorting, v3.0 Feb 15, 2018
@QuLogic QuLogic added the Py3k label Feb 18, 2018
@anntzer anntzer force-pushed the boundmethodproxy-like-weakmethod branch from 28fd2d7 to fb6b895 Compare May 7, 2018 01:44
@anntzer
Copy link
Contributor Author

anntzer commented May 7, 2018

rebased

@anntzer anntzer force-pushed the boundmethodproxy-like-weakmethod branch 3 times, most recently from 7e682ba to ad09280 Compare May 7, 2018 01:51
# Note proxy not needed in python 3.
# TODO rewrite this when support for python2.x gets dropped.
proxy = _BoundMethodProxy(func)
self._func_cid_map.setdefault(s, {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pros / cons of using ismthod vs try:....except:... on attempting to create the WeakMethod?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited accordingly.
As mentioned elsewhere I believe quite strongly that the use of weakmethod semantics is pretty silly anyways...

@anntzer anntzer force-pushed the boundmethodproxy-like-weakmethod branch from ad09280 to 04ebedc Compare May 7, 2018 16:39
@anntzer anntzer force-pushed the boundmethodproxy-like-weakmethod branch from 04ebedc to 85e07fb Compare June 24, 2018 22:06
@jklymak jklymak closed this Jul 9, 2018
@jklymak jklymak reopened this Jul 9, 2018
@tacaswell
Copy link
Member

Circle builds the commit on the branch (rather than the commit from doing the merge) so those won't fix them selves.

@@ -0,0 +1,6 @@
`CallbackRegistry` now stores callbacks using stdlib's `WeakMethods`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be WeakMethod

````````````````````````````````````````````````````````````````````

In particular, this implies that ``CallbackRegistry.callbacks[signal]`` is now
a mapping of callback ids to `WeakMethods` (i.e., they need to be first called
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also WeakMethod

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed x2

Code that used to call `_proxy(...)` now needs to call `_proxy()(...)`.

Instead of catching a ReferenceError, that could be either raised by a
failure to dereference the proxy, or by the underlying callable, one can
now check that `_proxy()` does not return None (to distinguish between
the two cases).

This is the same design as the stdlib's WeakMethod.
@anntzer anntzer force-pushed the boundmethodproxy-like-weakmethod branch from 85e07fb to 5257c4f Compare July 10, 2018 11:59
return self._hash


def _exception_printer(exc):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we need this anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still there (line 65) and unchanged, the diff is just confused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, great sorry for the noise.

@efiring efiring merged commit 991f996 into matplotlib:master Jul 23, 2018
@anntzer anntzer deleted the boundmethodproxy-like-weakmethod branch July 23, 2018 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants