[capycli] Fix ComparableVersion.__ne__ returning False for non-ComparableVersion objects#223
Open
prajakta128 wants to merge 1 commit into
Open
[capycli] Fix ComparableVersion.__ne__ returning False for non-ComparableVersion objects#223prajakta128 wants to merge 1 commit into
prajakta128 wants to merge 1 commit into
Conversation
…ableVersion objects
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.
Problem
ComparableVersion.__ne__incorrectly returnsFalsewhen the right-handoperand is not a
ComparableVersioninstance (e.g. a plainstr,int,or
None).This means expressions like:
All of these should return
Truebecause the objects are clearly not equal.This is a silent correctness bug — no exception is raised, just a wrong answer.
Root Cause
The
__ne__method copied the early-return guard from__eq__:In
__eq__, returningFalsefor a type mismatch is correct — two objectsof different types are not equal. But
__ne__is the logical inverse, so itmust return
Truefor the same case.Fix
Changed
return False→return Truein the isinstance guard of__ne__:Test Added
Added
test_ne_with_non_comparable_versionintests/test_comparable_version.pycovering comparison against
str,int, andNone— all cases that previouslyreturned the wrong result.
Impact
Any code that uses
!=to compare aComparableVersionagainst a plain stringor other type would silently get the wrong result. Since version values commonly
arrive as plain strings from JSON or CLI arguments, this bug could cause
incorrect filtering or deduplication of components without any visible error.