On 1 April 2018 at 02:58, Jeroen Demeyer <j.deme...@ugent.be> wrote:
> On 2018-03-31 18:09, Steven D'Aprano wrote:
>> Seems to me that if you want a fast, exact (no subclasses) check, you
>> should use "type(obj) is Class" rather than isinstance. If the *only*
>> reason to prohibit subclassing is to make isinstance a bit faster,
>> I don't think that's a good enough reason.
>
> I didn't really mean "isinstance" literally, I was mostly thinking of the C
> API. I agree that it's not clear.
>
> Do you happen to know why the existing function classes in Python disallow
> subclassing? I assumed that it was for exactly this reason.

Disallowing subclasses is a simplifying assumption for builtin types,
since it means they don't need to account for subclasses potentially
failing to enforce class invariants.

That said, allowing Cython/CFFI/etc to use the existing fast paths for
native Python functions and/or builtin C functions is a reasonable
justification for flipping that switch and doing the extra work needed
to make it robust - it's just likely to involve adding a number of
`*_CheckExact()` calls in various places.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to