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

Get rid of "wrapper_descriptors" and "method-wrapper"s #714

Open
markshannon opened this issue Jan 3, 2025 · 1 comment
Open

Get rid of "wrapper_descriptors" and "method-wrapper"s #714

markshannon opened this issue Jan 3, 2025 · 1 comment

Comments

@markshannon
Copy link
Member

>>> type(int.__add__)
<class 'wrapper_descriptor'>
>>> type((0).__add__)
<class 'method-wrapper'>

Compare to

>>> type(int.bit_count)
<class 'method_descriptor'>
>>> type((0).bit_count)
<class 'builtin_function_or_method'>

Wrapper descriptors and method wrappers are artifacts of the implementation. Ideally they would not exist and we would get

>>> type(int.__add__)
<class 'method_descriptor'>
>>> type((0).__add__)
<class 'builtin_function_or_method'>

We would like these wrapper descriptors to be method descriptors in order to simplify optimization and generally reduce the number of special cases.

There are two obstacles to doing this.

  1. These two types are exposed in the types module, so we cannot remove them altogether. Maybe we could make types.WrapperDescriptorType a subclass of method descriptor to simplify things, or just make types.WrapperDescriptorType an alias?
  2. There is no way to efficiently wrap a binary C function in a method descriptor. This is easily fixed by adding a METH_OO flag for functions taking two arguments enabling effective specialization of these functions
@JelleZijlstra
Copy link
Contributor

These two types are exposed in the types module, so we cannot remove them altogether. Maybe we could make types.WrapperDescriptorType a subclass of method descriptor to simplify things, or just make types.WrapperDescriptorType an alias?

There's precedent for this: types.LambdaType is an alias for types.FunctionType, and types.BuiltinMethodType and types.BuiltinFunctionType both point to builtin_function_or_method (I think they were different in Python 2?). If your proposal in this issue works out, I think aliasing the names in types.py would be a good solution.

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

No branches or pull requests

2 participants