This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients gvanrossum, rhettinger, serhiy.storchaka
Date 2021-11-12.18:01:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1636740086.94.0.717754704214.issue45791@roundup.psfhosted.org>
In-reply-to
Content
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().
History
Date User Action Args
2021-11-12 18:01:26rhettingersetrecipients: + rhettinger, gvanrossum, serhiy.storchaka
2021-11-12 18:01:26rhettingersetmessageid: <1636740086.94.0.717754704214.issue45791@roundup.psfhosted.org>
2021-11-12 18:01:26rhettingerlinkissue45791 messages
2021-11-12 18:01:26rhettingercreate