-
Notifications
You must be signed in to change notification settings - Fork 0
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
Isolating and injecting the dependency on varys #3
Conversation
agate/agate/i_message_retrieval.py
Outdated
from typing import Any, List | ||
|
||
|
||
class iMessageRetrieval: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the risk of bikeshedding, I wondered why you've called this iMessageRetrieval
? My instinct is for something like BaseMessageRetrieval
(or even BaseMessageRetriever
), indicating this is a base class (i.e., should be subclassed).
I can't quite decide if you mean for this to be an abstract class or not. The design feels to me like you want it to be an abstract class but then you create instances in the tests. (I need to have a look at how Mock()
works.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect you instantiate iMessageRetrieval
in the tests because the retriever has to be that kind of object to satisfy the type hint, but you could redefine the functions in EmptyMessageRetrieval
too (or maybe define a MockMessageRetrieval
if we expect more tests that need the mocking).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this is probably my instinct to try to implement interfaces/protocol classes in python whereas python just uses base classes for everything. (I'm doing a dependency injection talk in a few weeks, discussing the approach), I'll look further into python conventions and get back to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to impose that classes can be instantiated unless some functions are implemented, I think you can use the Abstract Base Class module in the standard library but I've never used it myself. I think what you've done is reasonably "Pythonic".
If this did become an abstract base class, then I think you'd have to use EmptyMessageRetrieval
and override its functions the same way you're currently doing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@warrickball I found Protocols which seem to be the python method, I've changed the name and made it a protocol https://typing.readthedocs.io/en/latest/spec/protocol.html#protocols
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! This (and the comparison with abstract base classes) sounds like demo content to me. 😉
No description provided.