Message402562
Because __instancecheck__ of _ProtocolMeta uses hasattr() and getattr(), both of which evaluate property attributes, calling isinstance() with an object and a class that inherits typing.Protocol evaluates the input object's properties in some cases.
The attached testcases include three cases of checking subtype relationship of an instance (having a property "x" that may raise RuntimeError on evaluation) and following three protocol classes;
(1) a protocol class having "x" as a property,
(2) a protocol class having "x" as a data attribute, and
(3) a protocol class having "x" as a class property that raises
RuntimeError on evaluation (>= python 3.9 only).
Expected behavior:
1. The isinstance(obj, Protocol_class) does not evaluate anything but just checks existence of attribute names.
2. All cases in the attached testcases run without any error
Thank you very much in advance. |
|
Date |
User |
Action |
Args |
2021-09-24 13:25:15 | daitakahashi | set | recipients:
+ daitakahashi |
2021-09-24 13:25:14 | daitakahashi | set | messageid: <1632489914.89.0.766542444973.issue45282@roundup.psfhosted.org> |
2021-09-24 13:25:14 | daitakahashi | link | issue45282 messages |
2021-09-24 13:25:14 | daitakahashi | create | |
|