Skip to content
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

nb_bound_method: add introspection attributes and fix surprising behavior around wrapper descriptors #216

Merged
merged 2 commits into from
May 24, 2023

Conversation

oremanj
Copy link
Contributor

@oremanj oremanj commented May 23, 2023

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 but obj.method.__call__() would not (it would need obj.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 want nb_func's version even though the attribute does exist in nb_bound_method's class dict as well. This is necessary to support __self__ and __func__ but I think it's a good idea regardless.

@oremanj
Copy link
Contributor Author

oremanj commented May 23, 2023

CI failure is the usual windows stderr-capturing flake.

@wjakob
Copy link
Owner

wjakob commented May 24, 2023

Nice, I like it -- thanks!

@wjakob wjakob merged commit 0a6f8f3 into wjakob:master May 24, 2023
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.

2 participants