Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding runtime_checkable to AttrsInstance #1388

Open
ryan-minato opened this issue Dec 23, 2024 · 1 comment
Open

Adding runtime_checkable to AttrsInstance #1388

ryan-minato opened this issue Dec 23, 2024 · 1 comment
Labels

Comments

@ryan-minato
Copy link

Is it possible to add the runtime_checkable decorator to AttrsInstance protocol?

class AttrsInstance(Protocol):
pass

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.

@hynek
Copy link
Member

hynek commented Jan 12, 2025

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__?

@hynek hynek added the Feature label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants