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

The example with typing.Protocol doesn't work with typehints. #1

Open
CaffeineDuck opened this issue Dec 26, 2023 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@CaffeineDuck
Copy link
Owner

class IMailService(ty.Protocol):
    def send_mail(self, subject: str, to: str) -> None:
        ...

@inject_args_deps
def business_logic(mail_service=Injectable(IMailService)):
    mail_service.send_mail("Hello", "world") # type of mail_service: Injectable[IMailService]
class IMailService:
    def send_mail(self, subject: str, to: str) -> None:
        ...


@inject_args_deps
def business_logic(mail_service=Injectable(IMailService)):
    mail_service.send_mail("Hello", "world") # type of mail_service: IMailService

The second type is desirable, but it doesn't work when the Injectable class in a typing.Protocol.

@CaffeineDuck CaffeineDuck self-assigned this Dec 26, 2023
@CaffeineDuck CaffeineDuck added the bug Something isn't working label Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant