<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 27 September 2017 at 18:08, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 9/27/2017 5:28 AM, Ivan Levkivskyi wrote:<br>
</span><span class=""><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It is proposed to add two special methods ``__class_getitem__`` and<br>
``__subclass_base__`` to the core CPython for better support of<br>
generic types.<br>
</blockquote>
<br></span>
I would not be concerned about anyone (mis)using reserved words.<br>
<br></blockquote><div><br></div><div>These methods are quite specific (especially __subclass_base__) so there are two points:</div><div><br></div><div>* I would like to say that there are less backwards compatibility guarantees. Only the documented use</div><div>  is guaranteed to be backwards compatible, which is in this case Iterable[int] etc.</div><div><br></div><div>* I don't want to "advertise" these methods. I could imagine someone will be unpleasantly surprised when <br></div><div>  finding these while reading someone other's code.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If the new methods were for general use, I would question making them automatically class methods.  Having __new__ automatically being a static method is convenient, but occasionally throws people off.  But if they were only used for typing, perhaps it is ok.  On the other hand, I expect that others will use __class_getitem__ for the same purpose -- to avoid defining a metaclass just to make class[something] work.  So I question defining that as 'typing only'.<br>
<br></blockquote><div><br></div><div>I think we would rather want to limit the number of use cases for SomeClass[int], so that one doesn't need to guess if it is a generic class or something else.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Without rereading the PEP, the use case for __subclass_base__ is not clear to me.  So I don't know if there are other uses for it.<span class="HOEnZb"><font color="#888888"><br>
</font></span></blockquote><div><br></div><div>The __subclass_base__ method is needed to avoid making the result of Iterable[int] a class object. Creating new class objects on</div><div>every subscription is too expensive. However, these objects must be subclassable, so that the only way is to introduce this new method.</div><div>For example:</div><div><br></div><div>class Iterable:</div><div>    def __class_getitem__(cls, item):</div><div>        return GenericAlias(cls, item)</div><div><br></div><div>class GenericAlias:</div><div>    def __init__(self, origin, item):</div><div>        self.origin = origin</div><div>        self.item = item<br></div><div>    def __subclass_base__(self, bases):</div><div>        return self.origin</div><div><br></div><div>class MyIterable(Iterable[int]):</div><div>    ...</div><div><br></div><div>Real code will be more complex, but this illustrates the idea. I don't know other use cases where one</div><div>would want to allow non-classes in base classes list.<br></div><div><br></div><div>Thanks for comments!</div><div><br></div><div>--</div><div>Ivan</div><div><br></div><div><br></div></div></div></div>