Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:
I did a scan of the standard library and code in the wild. It looks like almost all uses are in metaclasses (which makes sense because that matches the AppendableSequence example in PEP 3119). However, the typing module does have some cases of __instancecheck__ being used in regular classes. AFAICT that code is completely inoperative and there is no way for it to ever get called by isinstance(). I think people who __instancecheck__ in regular classes aren't noticing that their code isn't being called at all. The likely reasons are that isinstance() has a fast path for exact type matches and type() defines an __instancecheck__ in a reasonable way. So unless someone tests a case not already covered by those two paths, they won't notice the dead code. The two cases in typing.py are _Final and _BaseGenericAlias. The __instancecheck__ methods in those were written by Ivan and by GvR likely with the expectation that that code would by called by isinstance(). ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45791> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com