Retrofitting Dependency Injection System With Pyright: Force Non-Data Protocol Check #11357
Unanswered
ianjosephwilson
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a protocol setup sort of working as below for dependency injection. The scanning and registration is done via
venusianwhich sort of side steps the regular flows which is good... and bad. There is no "concrete" connection between the implementation,BundleService, and the "interface" (protocol),BundleProtocol. Is there a way to tell pyright to just check the implementation matches the protocol without doing some sort of manual check after every declaration?A manual check,
check_service(), is done in the example below. I could move this "manual" check into the decorator but it is still using a weaker signature check provided by python instead of pyright's more robust signature checking (AFAIK). I don't know what to search for, if this is super obvious and already exists, maybe something likeclass BundleService: # pyright: force_check(BundleProtocol)?So in more plain-speak I'm looking for something that does this:
pyright please always statically check that this class is implementing the non-data (methods only) protocol provided in this protocol
Here is a rough example of what I have now:
Define Service
Define Protocols
Use service
Beta Was this translation helpful? Give feedback.
All reactions