Closed
Description
Bug report
Bug description:
#103034 added some protections around isinstance
checks of runtime_checkable
Protocols
using inspect.getattr_static
. This uses inspect._check_instance
which uses object.__getattribute__(obj, "__dict__")
, which fails for bound instance methods (although obj.__dict__
does work), so they cannot fulfill runtime_checkable
Protocols
anymore.
from typing import Protocol, runtime_checkable
@runtime_checkable
class Labelled(Protocol):
label: str
class A:
def f(self):
pass
A.f.label = "f"
a = A()
print(a.f.__dict__) # {'label': 'f'}
print(object.__getattribute__(a.f, "__dict__")) # AttributeError
assert isinstance(a.f, Labelled) # AssertionError
Is this an intended/known change? Could it be noted in the changelog here as an example of case that will no longer work?
Created from #103034 (comment)
cc @AlexWaygood
CPython versions tested on:
3.12
Operating systems tested on:
Linux