[Python-Dev] Accepting PEP 560 -- Core support for typing module and generic types

Yury Selivanov yselivanov.ml at gmail.com
Thu Dec 14 19:25:58 EST 2017


On Thu, Dec 14, 2017 at 7:03 PM, Guido van Rossum <guido at python.org> wrote:
> A slot is pretty expensive, as *every* class in existence will be another 8
> bytes larger (and possibly more due to malloc rounding). So unless we find
> that there's a significant performance benefit I think we should hold back
> on this. IIRC Ivan has already measured an order of magnitude's speedup
> (well, 7x), so we may not need it. :-)

My motivation to add the slot wasn't the performance: it's just not
possible to have a class-level __getitem__ on types defined in C. The
only way is to define a base class in C and then extend it in
pure-Python.  This isn't too hard usually, though.

BTW that slot could also host the new __mro_entries__ method, and,
potentially, other magic methods like __subclasscheck__ and
__instancecheck__.

Yury


More information about the Python-Dev mailing list