-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Extract logic from find_best_candidate and find_all_candidate to static methods #9681
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
Conversation
This is a good start, but needs more work to achive the goal. My concern to The proper way to resolve this would be to ensure |
(Converting to draft so this don’t accidentally get merged.) |
Thank you for the feedback and explanation on how to tackle this issue. In the upcoming weeks, we'll try to make the pr ready. |
@uranusjr Would it be a good solution to make |
It should be, but I’d favour the approach less myself. The amount of work is likely similar, but hashability affects much more than just the cachability of the two functions. Conceptually, both |
How would your approach look like? Because if we look at for example the |
What I have in mind is to not pass hashable objects into those functions, but those objects shouldn’t be |
@uranusjr we refactored For the static functions, instead of using the When disassembling |
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.
The general approach looks good to me! There are some coding style improvements I would like to se though (commented inline).
Regarding _logged_links
, the easiest solution is probably to make get_install_candidate_static
return Tuple[Optional[InstallationCandidate], Set[Link]]
instead, where the second member is the newly logged links, and update it back into PackageFinder._logged_links
after calling.
BTW, static methods do not need to be called by their class name, and can still be called with self
. This will make the code (and the generated diff) cleaner.
Returns elements of links in order, non-egg links first, egg links | ||
second, while eliminating duplicates | ||
""" | ||
return PackageFinder._sort_links_static(links) |
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.
Do we still need this function?
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.
Yes, because this function is called in evaluate_links_static
.
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.
What I meant is, can we just call _sort_links_static
directly there and get rid of this function? It does not do anything from what I can tell.
""" | ||
link_evaluator = self.make_link_evaluator(project_name) | ||
|
||
package_finder_tuple = self.get_state_as_tuple(True) |
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.
It’d be much clearer to make True
a keyword argument instead.
@functools.lru_cache(maxsize=None) | ||
def find_best_candidate_static( |
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.
It’d be clearer to name this a private function (adding a leading _
). There are other functions that can be similarly changed to signify they are only internal and not called elsewhere (which improves maintainability).
We saw that |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
c596437
to
28b08a0
Compare
Closes #9084
Extract the logic from package_finder.find_best_candidate and package_finder.find_all_candidate to static methods.
#9078 (comment)
Co-authored by ThijmenL98