Message406230
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 |
|
Date |
User |
Action |
Args |
2021-11-12 18:43:26 | rhettinger | set | recipients:
+ rhettinger, gvanrossum, serhiy.storchaka |
2021-11-12 18:43:26 | rhettinger | set | messageid: <1636742606.33.0.065777773807.issue45791@roundup.psfhosted.org> |
2021-11-12 18:43:26 | rhettinger | link | issue45791 messages |
2021-11-12 18:43:26 | rhettinger | create | |
|