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

Isolating and injecting the dependency on varys #3

Merged
merged 9 commits into from
Nov 14, 2024

Conversation

ergoregion
Copy link
Collaborator

No description provided.

@ergoregion ergoregion self-assigned this Nov 13, 2024
from typing import Any, List


class iMessageRetrieval:

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.)

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).

Copy link
Collaborator Author

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.

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.

Copy link
Collaborator Author

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

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. 😉

@ergoregion ergoregion merged commit 9a36efd into main Nov 14, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants