[cppyy] Preserve C++ docstring when uninformative PyExceptions/no traceback#21989
Merged
dpiparo merged 1 commit intoroot-project:masterfrom Apr 22, 2026
Merged
[cppyy] Preserve C++ docstring when uninformative PyExceptions/no traceback#21989dpiparo merged 1 commit intoroot-project:masterfrom
dpiparo merged 1 commit intoroot-project:masterfrom
Conversation
Test Results 22 files 22 suites 3d 7h 28m 57s ⏱️ For more details on these failures, see this check. Results for commit c74f746. ♻️ This comment has been updated with latest results. |
Contributor
Author
|
@guitargeek I see these failures that seem unrelated: Any idea what is causing it? I don't see them on master |
Contributor
|
Probably related to this PR: #21761 Can you rebase on master and push? Just to get a fresh incremental |
…ceback This follows up on root-project#18163 which broke test `test_fragile:test10_documentation` on the compiler-research forks since we lose a C++ side error. This patch resolves the issue by preserving C++ errors when that information can be actually useful, either when the PyException is uninformative, or there is no Python traceback. We completely preserve the intended behaviour of the original commit: ```py import cppyy def inner_func(x): raise ValueError("hello") def func(x): return inner_func(x) cpp_wrapper = cppyy.gbl.std.function["double(double)"](func) cpp_wrapper(3) ``` resulting in something like: ``` Traceback (most recent call last): File "/home/ajomy/cppyy-interop-dev/CppInterOp/cppyy/test/test_err.py", line 11, in <module> cpp_wrapper(3) File "/home/ajomy/cppyy-interop-dev/CppInterOp/cppyy/test/test_err.py", line 7, in func return inner_func(x) ^^^^^^^^^^^^^ File "/home/ajomy/cppyy-interop-dev/CppInterOp/cppyy/test/test_err.py", line 4, in inner_func raise ValueError("hello") ValueError: hello ``` instead of also appending `ValueError: double std::function<double(double)>::operator()(double __args) => ValueError: hello` to the err message But also retaining the C++ docstring context in cases as seen in `test_fragile:test10_documentation` where we expect the docstring when calling the following overload: ```cpp class D { public: virtual int check() { return (int)'D'; } virtual int check(int, int) { return (int)'D'; } void overload() {} void overload(no_such_class*) {} void overload(char, int i = 0) {} // Reflex requires a named arg void overload(int, no_such_class* p = 0) {} }; ``` as `d.overload(None)`: ``` assert "void fragile::D::overload(char, int i = 0)".replace(" ", "") in err_msg ```
Contributor
Author
|
cc @dpiparo this is ready to be landed for the release. The recent rebase should make all checks green. |
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.
This follows up on #18163 which broke test
test_fragile:test10_documentationon the compiler-research forks since we lose a C++ side error. This patch resolves the issue by preserving C++ errors when that information can be actually useful, either when the PyException is uninformative, or there is no Python traceback. We completely preserve the intended behaviour of the original commit:resulting in something like:
instead of also appending
ValueError: double std::function<double(double)>::operator()(double __args) => ValueError: helloto the err messageBut also retaining the C++ docstring context in cases as seen in
test_fragile:test10_documentationwhere we expect the docstring when calling the following overload:as
d.overload(None):From compiler-research/CPyCppyy@7d6f1b3