<div dir="ltr">This particular breakage is explicitly listed in PEP 560, see an example with List and List[int] in <a href="https://www.python.org/dev/peps/pep-0560/#backwards-compatibility-and-impact-on-users-who-don-t-use-typing">https://www.python.org/dev/peps/pep-0560/#backwards-compatibility-and-impact-on-users-who-don-t-use-typing</a><div><br></div><div>In general, isinstance() with typing types should be avoided when possible (Mark Shannon who is the BDFL delegate for PEP 484 wanted to prohibit it completely, but in the end we kept only the bare minimum, like your first example).</div><div><br></div><div>When designing/implementing PEP 560 I realised it will be impossible to keep 100% backwards compatibility. I tried to preserve 99% of public APIs, but since isinstance() is already discouraged, it fell into remaining 1%.</div><div><br></div><div>A possible workaround is to use `typing_inspect` library on PyPI (disclaimer: I originally wrote it). You can use `get_origin()` function to extract the runtime class that corresponds to a given type. It works with both 3.6 and 3.7 and tries its best to return the relevant runtime class (with few exceptions, see docstring), for every version, for example on Python 3.7 `get_origin(List[int])` return `list`. The return of get_origin() should be usable in all runtime context including `isinstance()`.</div><div><br></div><div>Btw, I actually like the new behaviour. After PEP 560 types are no more classes, which emphasises that they should be used in static context, if one wants to do something in runtime, one needs to use an explicit conversion to a runtime class.</div><div><br></div><div>--</div><div>Ivan</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 23 June 2018 at 23:10, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>First, the typing module is still provisional, so there is no strict backwards compatibility guarantee.</div><div><br></div><div>With that out of the way, I can reproduce your problem, and I assume it's caused by the implementation of PEP 560, which is meant to speed up the typing module (among other goals).</div><div><br></div><div>I'm wondering about your claim that this breaks many "libraries that use annotations". Most code using annotations would not need to use issubclass() in this way. Where exactly did you encounter this?</div><div><br></div><div>I'm CC'ing Ivan Levkivskyi, who knows the relevant code better and will be able to explain whether this is an oversight or an intentional regression.<br></div></div><br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Sat, Jun 23, 2018 at 2:59 PM Rokker Ruslan <<a href="mailto:rokkerruslan@yandex.com" target="_blank">rokkerruslan@yandex.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div><div>Python 3.7 in the status of RC, but I do not see information about the fact that python3.7 is backwards incompatible with python3.5.</div><div> </div><div>$ ~ python3.5</div><div>Python 3.5.2 (default, Nov 23 2017, 16:37:01) </div><div>[GCC 5.4.0 20160609] on linux</div><div>Type "help", "copyright", "credits" or "license" for more information.</div><div>>>> from typing import List</div><div>>>> class MyList(list):</div><div>...     pass</div><div>... </div><div>>>> issubclass(MyList, List)</div><div>True</div><div>>>> issubclass(List, MyList)</div><div>False</div><div>>>></div><div> </div><div>$ ~ python3.7</div><div>Python 3.7.0rc1+ (heads/3.7:3747dd16d5, Jun 22 2018, 22:53:42) </div><div>[GCC 5.4.0 20160609] on linux</div><div>Type "help", "copyright", "credits" or "license" for more information.</div><div>>>> from typing import List</div><div>>>> class MyList(list):</div><div>...     pass</div><div>... </div><div>>>> issubclass(MyList, List)</div><div>True</div><div>>>> issubclass(List, MyList)</div><div>Traceback (most recent call last):</div><div>  File "<stdin>", line 1, in <module></div><div>TypeError: issubclass() arg 1 must be a class</div><div>>>></div><div> </div><div>And so with all types of "typing" module.</div><div>This breaks down many libraries that use annotations as part of the functionality if we now can't use typing.* into issubclass function.</div></div></div></div>______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>guido%40python.org</a><span class="HOEnZb"><font color="#888888"><br>
</font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br clear="all"><br>-- <br><div dir="ltr" class="m_-196025465278582137gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</font></span></blockquote></div><br></div>