[Python-ideas] Stub class for Generic to further improve PEP 560

Ivan Levkivskyi levkivskyi at gmail.com
Fri Dec 1 05:10:57 EST 2017

On 1 December 2017 at 00:34, Ilya Kulakov <kulakov.ilya at gmail.com> wrote:

> Anyway, my expectation is that going along this way (i.e. removing all
> runtime API apart from a necessary minimum)
> will give a minor speed-up as compared to PEP 560 at the cost of a
> breaking change (even for small number of developers).
> I don't think the change will be breaking: usage of this class will be
> entirely voluntarily and does not replace typing.Generic
If you propose an additional class, then yes, it is non-breaking, but I
still don't see much value given a minor performance improvement.

> PEP 560 already gives overhead of 80% as compared to normal classes in
> worst case scenario
> (empty body with a single generic base). This is actually less than for
> ABCs (they can give up to 120% in worst case scenario).
> GenericMeta inherits from ABCMeta. Do you mean that it will be removed
> after 560 lands?
Yes, GenericMeta will be removed.

> Moreover, performance is not a single motivation for PEP 560, there are
> other arguments such as metaclass conflicts which will
> not be solved without the machinery proposed by the PEP.
> Perhaps you can consider designing Generic / GenericMeta in a way that
> will allow end user to create GenericStub-alike class without much trouble?

This can be done, but the hardest part here is not to make the runtime
changes, but to get the support of all
static type checkers (they need to understand what GenericStub means and
add all the necessary special casing).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171201/f3ed5e72/attachment.html>

More information about the Python-ideas mailing list