For example:
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)
will raise the RuntimeError
This is an issue, for example, if myproperty is an expensive call, has unwanted side effects, or excepts outside of a context manager
Linked PRs
For example:
will raise the
RuntimeErrorThis is an issue, for example, if
mypropertyis an expensive call, has unwanted side effects, or excepts outside of a context managerLinked PRs
isinstance()checks ontyping.runtime_checkableprotocols #102449isinstance()checks ontyping.runtime_checkableprotocols (GH-102449) #102592isinstance()checks ontyping.runtime_checkableprotocols (GH-102449) #102593inspect.getattr_staticintyping._ProtocolMeta.__instancecheck__#103034