On Fri, May 8, 2020 at 3:47 PM Steven D'Aprano <st...@pearwood.info> wrote:

> 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?
>

Yes, that is correct.

I think Serhiy's idea has merit. The key thing is that, even though it
seems an obscure CPython implementation detail, it actually affects the
language definition (or at least the specification of selected stdlib
methods) because when we say that e.g. bytes.index(bytearray(...), b)
works, we should document it in the stdlib docs, and other Python
implementations will have to support this too.

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WNEF3LW5JSZJEQLO633U6ZXTXYCSMJEV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to