[capycli] Fix ComparableVersion.__ne__ returning False for non-ComparableVersion objects#223
[capycli] Fix ComparableVersion.__ne__ returning False for non-ComparableVersion objects#223prajakta128 wants to merge 1 commit into
Conversation
…ableVersion objects
b48f5b4 to
00517f0
Compare
|
@prajakta128, thanks for your contribution! The change itself looks good to me, I agree that default return value of ne should be negated compared to eq! It was however still failing flake8 tests, so I pushed a small fix and squased your two commits into one. Just one question, did you find this by pure code anaylsis or did this cause some real problems when using CaPyCli? In the latter case, we should mention them in the ChangeLog. @tngraf, assigning to you for final decision, from my side it can be merged. |
@gernot-h Thank you for the review, and for fixing the flake8 issue and To answer your question — I identified this issue through code review of Thank you for taking the time to review this contribution. |
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.