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 daitakahashi
Recipients daitakahashi
Date 2021-09-24.13:25:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632489914.89.0.766542444973.issue45282@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-09-24 13:25:15daitakahashisetrecipients: + daitakahashi
2021-09-24 13:25:14daitakahashisetmessageid: <1632489914.89.0.766542444973.issue45282@roundup.psfhosted.org>
2021-09-24 13:25:14daitakahashilinkissue45282 messages
2021-09-24 13:25:14daitakahashicreate