perf: Version.__eq__#951
Open
radoering wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Using
self.release._compare_keyinPEP440Version._make_compare_keytightens coupling to the internal representation ofRelease; consider exposing a public accessor (e.g.release.compare_key) or helper to avoid depending on a private attribute. - The float sentinels (
float('inf')/float('-inf')) and-infin the local segment appear multiple times; consider centralizing them as named constants (similar to_INF_TAG/_NEG_INF_TAG) to avoid magic values and keep comparison semantics consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Using `self.release._compare_key` in `PEP440Version._make_compare_key` tightens coupling to the internal representation of `Release`; consider exposing a public accessor (e.g. `release.compare_key`) or helper to avoid depending on a private attribute.
- The float sentinels (`float('inf')` / `float('-inf')`) and `-inf` in the local segment appear multiple times; consider centralizing them as named constants (similar to `_INF_TAG` / `_NEG_INF_TAG`) to avoid magic values and keep comparison semantics consistent.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes that make comparisons of versions faster:
inline the most common case in
Version.__eq__and put it at the topAdmittedly, this is a minor regression in terms of maintainability because it kind of duplicates
__eq__of the parent class but I think it is small and "risk-free enough" so that it is acceptable (the "duplicated" code is only one line and, moreover, something that is unlikely to change in the parent class because it is literally the comparison of the compare keys).use simple types instead of classes in the
_compare_keyofPEP440VersionI think this change is just as good as before in terms of maintainability.