<div dir="ltr"><p dir="ltr">Mostly historical reasons I guess, we started with static 
types because most class extension examples were using it, and it worked
 for all we did at the time (including the __class__ assign trick). We 
then got hit by the change, and solved the issue by patching python. <br>
Now keeping our own patched CPython is still perfectly viable, but there
 are disadvantages to not using the off-the-self interpreter: it prevent interacting with other proprietary libs within a single 
interpreter. So that would be plan C (BTW having a common interpreter is a necessary condition, but far from enough...)</p>
<p dir="ltr">Plan A was to push the idea that extension type behavior 
could be more tunable: ATM you choose between static and heap type, and 
it comes with a bunch of other non obvious differences, whose 
combination is not necessarily the best for your use case or preferences
 (see for example <a href="http://grokbase.com/t/python/python-dev/097twacntz/py-tpflags-heaptype-too-overloaded" target="_blank">http://grokbase.com/t/python/python-dev/097twacntz/py-tpflags-heaptype-too-overloaded</a> ).<br>
I still think it's s good idea to allow for more tunable behavior, and 
certainly not use heap type as a marker for things not obviously 
related, but as it did not gather traction 10y ago, nor this time 
either, so I will not push for plan A. Time has teached me it is better to wait for the proposal come back from another source, than invest too much time in it if support, or at least discussion is not strong from the start. It will probably come back and pass later, in a form or another ( PEP225/465 ;-p )<br></p>
<p dir="ltr">Plan B is to see how much additional work it will be 
to use heap type, and if we do not suffer from it's other properties. If
 we end up requiring another patch, bye bye plan B and back to the 
original patch.<br></p><br></div><br><div class="gmail_quote"><div dir="ltr">Le mer. 27 juin 2018 à 19:46, Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">So the question remains -- why not use a heap type?<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 27, 2018 at 2:05 AM Greg <<a href="mailto:gregory.lielens@gmail.com" target="_blank">gregory.lielens@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>As I introduced (a long time ago) this demand, let me add my grain of salt here.</div><div><br></div><div>The use case is pretty simple, and somewhat common when writing manually C extension class: The reason to write extension class is usually performance, or link into an existing library. <br></div><div>When doing this manually (instead of using automatic python-wrapping tools like boost, swig,...) you try to wrap the minimum amount of methods/accessors/...to your underlying c/c++ class, and replicate non-critical methods in python.</div><div> Moreover, extending your class by adding new methods is usually much more easy in Python, especially if it involve complex but not performance-bounded python-data manipulation.</div><div>Problem is to make those python-implemented methods avaible to instances of your extension class, especially when those instances are returned by the C layer of your extension. <br></div><div><br></div><div>The solution we choose was to  change the __class__ of each extension type instance to the python derived newclass implementing all those extra-methods.Not too difficult, a simple encapsulation of all methods returning extension-class instances is enough, and can be automated.<br></div><div>This solution is quite common I think, it translate something you do for python-class instances, but then you get  the __class__ assignment: only for heap types error.</div><div><br></div><div>The argument about sub-interpreters is a good one, but not really applicable for this use case: we really want to have one extension type (or a hierarchy of it) shared across all interpreter importing the extension, it just happen that instead of being implemented in pure C/C++, the extension is implemented in C/C++ and Python. The fact that the python parts will be seen everywhere is a feature, not a problem: you expect the replacement of C-implemented methods by Python-implemented method to be as transparent as possible.</div><div><br></div><div>Alternatives would be to use a  heap type for our C extensions classes (we need to check what it would imply, but it may be quite painless)</div><div>or use some form or delegation instead of assigning to __class__.</div><div>The later is not really painless, AFAIK, in term of coding complexity and possibly performance (extra lookups steps needed).</div><div><br></div><div>If there are other solutions or if delegation can be made as simple/efficient as the __class__ mechanism, it would be good to know, and it is I think valuable info for many people writing extension classes.<br></div><div>Anyway, my personal position on this has not changed in 10y and is in line with Eloi: I think that beeing a heaptype and allowing assigment to the  __class__ attribute of instances is indeed quite orthogonal..<br></div><div><br></div><div><br></div><div><br></div><div><code>.</code></div><div><code><br></code></div><div><code><br></code></div><div><code><br></code></div><div><code><br></code></div><div><code><br></code></div><code><span class="m_-1743292922411018672m_-525331663008962461gmail-pln"></span></code> <br></div>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="m_-1743292922411018672gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</blockquote></div>