On May 8, 2020, at 15:44, Steven D'Aprano
On Fri, May 08, 2020 at 10:46:45PM +0300, Serhiy Storchaka wrote:
I propose to add the METH_GENERAL flag, which is applicable to methods as METH_CLASS and METH_STATIC (and is mutually incompatible with them). If it is set, the check for the type of self will be omitted, and you can pass an arbitrary object as the first argument of the unbound method.
Does this effect code written in Python? As I understand, in Python code, unbound methods are just plain old functions, and there is no type-checking done on `self`.
py> class C: ... def method(self, arg): ... return (self,) ... py> C.method(999, None) (999,)
So I think your proposal will only affect builtin methods written in C. Is that correct?
Maybe the best way to see it is this: For classes implemented in Python, you have to go out of your way to typecheck self. For classes implemented in C, you have to go out of your way to _not_ typecheck self. It’s probably way too big of a change to make them consistent at this point, so Serhiy is just proposing a way to make it a lot easier for C methods to act like Python ones when you need them to. And, given that he has some solid use cases, it’s hard to see any problem with that.