Commit 4eaf83a
committed
[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.1 parent f1a9a19 commit 4eaf83a
1 file changed
Lines changed: 38 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
532 | 532 | | |
533 | 533 | | |
534 | 534 | | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | 535 | | |
552 | 536 | | |
553 | 537 | | |
| |||
592 | 576 | | |
593 | 577 | | |
594 | 578 | | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
608 | 583 | | |
609 | 584 | | |
610 | | - | |
611 | | - | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
612 | 602 | | |
613 | | - | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
614 | 620 | | |
615 | 621 | | |
616 | 622 | | |
| |||
0 commit comments