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

Suggestion: Allow for protocols to be used as interfaces #33

Closed
ewilazarus opened this issue Sep 28, 2024 · 3 comments
Closed

Suggestion: Allow for protocols to be used as interfaces #33

ewilazarus opened this issue Sep 28, 2024 · 3 comments

Comments

@ewilazarus
Copy link

Currently it seems like only abc.ABC classes can be used as interfaces.

It would be great to add support for typing.Protocols as well!

Happy to try to put a PR together, but might need some guidance.

@ewilazarus
Copy link
Author

Duplicates #3

@maldoinc
Copy link
Owner

Thanks for the interest in this. Registering a protocol with @abstract should already work but when registering a service, the code needs to associate the thing being registered with the given protocol.

The main thing to do here would be to update the registry register_{service,factory} methods and to update registration decorators with any new arguments.

@maldoinc
Copy link
Owner

A reason why I haven't prioritized this is also that I cannot quite get the typing to work as I want: When decorating a class or factory with @container.register(supports=SupportsFoo) ideally the type checker should flag if the thing being created does not actually adhere to the protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants