nb_bound_method: add introspection attributes and fix surprising behavior around wrapper descriptors #216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The introspection attributes
__self__
and__func__
provide better interface compatibility with regular Python bound methods, and can be cheaply supported by adding new entries in the existing member list.The previous wholesale forwarding of attribute accesses to the underlying
nb_func
produced surprising behavior when explicitly invoking dunder methods:obj.method()
would work butobj.method.__call__()
would not (it would needobj.method.__call__(obj)
). Same thing for__repr__
,__hash__
, etc. Fix this by checking the 'normal' attribute path before delegating to the contained method, except for__doc__
and__module__
where we wantnb_func
's version even though the attribute does exist innb_bound_method
's class dict as well. This is necessary to support__self__
and__func__
but I think it's a good idea regardless.