-
Notifications
You must be signed in to change notification settings - Fork 5
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
feature: make all classes in the common module hashable #39
base: master
Are you sure you want to change the base?
Conversation
- hashability and comparability is useful in many usecases, e.g. when using results as dict key - hashability could be achieved by setting frozen = True, but that would be an obstacle to backwards compatibility and makes it harder to understand the code, especially for people not familiar with pydantic - implementation of __eq__ is verbose to make it explicit, could use hash(self)==hash(other) as well - hash and comparison of Part classes as it generally has no real-world meaning and can be derived e.g. from an objects index in the parent route instance.
Everything else looks good for me but if we implement hash and eq for basic classes, we'll need to implement for all response classes too |
- a specific __eq__ implementation is only needed when some of the fields shall be excluded from comparison
Absolutely agree with you, and probably for a few others as well. I suggest keeping the PR here open until we step by step added hashability to more classes. I also added it to |
But where and how did you want to use them? I was planning to make them private and use only inside sdk to map requests |
That leads to an interesting point: I think that the use cases for the API can vary a lot so making the SDK as adaptable as possible is a useful thing. What I do is I don't use the original The concrete use case was to track which searches go through without an error as any Other use cases may be recreating searches/api request depending on the initial response. E.g. you want to find connections from A to B for each 10 minute time window in an hour, but instead of making 6 requests which will all return nothing if there are no connections at all it might make sense to first make a request with range_width=3600 and only if that is successfull make a more granular search. That means having to take apart a But that's just my usecase. Others may have different use cases. One of the issues I face when subclassing |
One more comment:
However in the end I need to make own calculations with the response, so when I receive route I might want to calculate the min time between public transport parts. I could use a function for that that accepts a Route instance or a list of |
Okey, thanks @MxMartin for you review, I'll think how to do it and add some new issue. If you need something from sdk, write it in issues, please, so we won't forget about it. And it'd be nice if you could share with us some code samples how you use our sdk and your modifications, so we'll know how to improve it. |
While working on the code I also did some refactoring to reduce duplication, i.e. I introduced an abstract base class for the parts which contains the fields that are common to all Part classes