-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Add instancemethod to types.py #80118
Comments
Having the ability to add binding behavior to any callable is an incredibly useful feature if one knows how to take advantage of it, but unfortunately, nothing that currently (publicly) exists comes close to filling the gap There really isn't anything else to say about it because it's simply amazing at what it does, and publicly exposing it has zero drawback that I could possibly imagine. if 1:
from functools import _lru_cache_wrapper, partial
method = type((lambda:0).__get__(0))
for cls in object.__subclasses__():
if cls.__name__ == 'instancemethod':
instancemethod = cls
break
del cls
class Object:
lrx = _lru_cache_wrapper(id, 0, 0, tuple)
imx = instancemethod(id)
smx = property(partial(method, id))
fnx = lambda self, f=id: f(self)
|
Could you expand on why instancemethod is amazing, other than that's it is apparently fast at something. |
I presume you aren't referring to this: from types import MethodType
How about starting with why you want this and what you will do with it? According to this post on StackOverflow:
Given that this is not used anywhere in CPython, the documentation for the C API specifically says it is not exposed to Python code, and the name is painfully misleading, we should assume that it is undocumented for a reason. It might help to persuade the core devs to expose it as part of the public Python API if you have a use-case for this. (And if so, I think it desperately needs to change the displayed name away from "instancemethod", since that's not what it returns.) See also # #73028. |
Also see #55985 about documenting the signatures. |
There are 3 issues here.
I am inclined to close this as insufficiently justified. Steven? @Irit? (#55985 would only be relevant here is 3 were done.) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: