attrs
attrs copied to clipboard
Adding runtime_checkable to AttrsInstance
Is it possible to add the runtime_checkable decorator to AttrsInstance protocol?
https://github.com/python-attrs/attrs/blob/598494a618410490cfbe0c896b7a544f6d23e0d9/src/attr/init.py#L37-L38
In my project, I am working on a decorator that automates converting a dict into an AttrsInstance.
To perform reflection checks on input definitions, I found myself needing to subclass AttrsInstance without modifying it—just to add the runtime_checkable decorator.
It would be incredibly helpful if the attrs library's definition already included runtime_checkable.
As @Tinche commented on your PR, this is not trivial, because runtime_checkable checks whether an instance fulfills the Protocol you defined and since AttrsInstance is empty, every class will conform.
Maybe it's possible if we switch to an abc with a dedicated __instancecheck__?