You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[CPyCppyy] Remove pointer-based fallback in CPPInstance equality check
The Python proxy for C++ objects previously implemented a fallback equality
comparison based on proxy type and the held C++ pointer address when no
C++ `operator==` / `operator!=` was available. This behavior was
misleading, because it made expressions like `a == b` appear to perform
a value comparison even though no corresponding C++ operator was
defined.
This patch removes the implicit pointer-based fallback and instead raises
a TypeError when equality is requested between two CPPInstance proxies for
which no C++ equality operator can be resolved. This avoids silently
changing semantics and makes unsupported comparisons explicit.
The only case where the pointer-based fallback is kept is for proxies of
the exact same type when at least one wraps a `nullptr`: in this case,
comparison continues to be performed on the pointer value, because
comparing by value would not be possible. This preserves existing cppyy
behavior in a case that is not semantically ambiguous. Although C++
would also allow comparisons between nullptr pointers of types related
by inheritance, broadening the rule would silently change previous cppyy
behavior, where such comparisons returned `False`.
To summarize: this change prevents ambiguous equality semantics while
avoiding silent behavior changes for existing code by raising a type
error in cases that are ambiguous or where previous behavior was
different from C++ semantics.
Closes#21347.
0 commit comments