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:43:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1636742606.33.0.065777773807.issue45791@roundup.psfhosted.org>
In-reply-to
Content
Here's an example in PEP 3119 that appears to work but actually bypasses the method:

from abc import ABCMeta, abstractmethod

class Sized(metaclass=ABCMeta):
    @abstractmethod
    def __hash__(self):
        return 0
    @classmethod
    def __instancecheck__(cls, x):
        print('Called')
        return hasattr(x, "__len__")
    @classmethod
    def __subclasscheck__(cls, C):
        return hasattr(C, "__bases__") and hasattr(C, "__len__")

$ python3.10 -i demo_3119.py
>>> isinstance([], Sized)
True
History
Date User Action Args
2021-11-12 18:43:26rhettingersetrecipients: + rhettinger, gvanrossum, serhiy.storchaka
2021-11-12 18:43:26rhettingersetmessageid: <1636742606.33.0.065777773807.issue45791@roundup.psfhosted.org>
2021-11-12 18:43:26rhettingerlinkissue45791 messages
2021-11-12 18:43:26rhettingercreate