
March 24, 2020
5:12 a.m.
On 24/03/20 3:43 pm, Dennis Sweeney wrote:
This was an attempt to ensure no one can do funny business with tuple or str subclassing. I was trying to emulate the ``PyTuple_Check`` followed by ``PyTuple_GET_SIZE`` and ``PyTuple_GET_ITEM`` that are done by the C implementation of ``str.startswith()``
The C code uses those functions for efficiency, not to prevent "funny business". PyTuple_GET_SIZE and PyTuple_GET_ITEM are macros that directly access fields of the tuple struct, and PyTuple_Check is much faster than a full isinstance check. There is no point in trying to emulate these in Python code. -- Greg