isinstance on runtime_checkable Protocol has side-effects for @property methods · Issue #102433 · python/cpython (original) (raw)

from typing import Protocol, runtime_checkable

@runtime_checkable class X(Protocol): @property def myproperty(self): ...

class Y: @property def myproperty(self): raise RuntimeError("hallo")

isinstance(Y(), X)

This is an issue, for example, if myproperty is an expensive call, has unwanted side effects, or excepts outside of a context manager