Commit f687d1d
committed
[CPyCppyy] Correctly propagate template argument name errors
In case the `Utility::ConstructTemplateArgs()` method fails to create
the C++ template names, it sets a useful Python exception that is
unfortunately not propagated, because the calling code in
`TemplateProxy.cxx` is ignoring it. This is fixed in this commit.
The place where the error is set is also moved from
`Utility::ConstructTemplateArgs()` to the actual implementation:
`AddTypeName()`. This means the error is set by the function that
actually has the context of the error, which is conceptually cleaner and
will allow us also to set more detailed errors for different failure
modes of `AddTypeName()`.
A unit test is also implemented.
Demo code:
```python
import cppyy
cppyy.cppdef("""
template<class T>
class Foo {};
template<class T, class Y=void>
auto make_foo () { return Foo<T>{}; }
template<class T, class Y=void>
auto make_foo (T x) { return Foo<T>{}; }
""")
cppyy.gbl.make_foo[set(), list()]()
```
Before:
```
cppyy.gbl.make_foo[set(), list()]()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
TypeError: Could not find "make_foo" (set cppyy.set_debug() for C++ errors):
Template method resolution failed:
Failed to instantiate "make_foo()"
Failed to instantiate "make_foo()"
```
After:
```
cppyy.gbl.make_foo[set(), list()]()
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
TypeError: could not construct C++ name from template argument set()
```
Note: this work is orthogonal to the rebase of `cppyy` on CppInterOp.1 parent 24fe57c commit f687d1d
File tree
3 files changed
+49
-3
lines changed- bindings/pyroot/cppyy
- CPyCppyy/src
- cppyy/test
3 files changed
+49
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
176 | 183 | | |
177 | 184 | | |
178 | 185 | | |
| |||
720 | 727 | | |
721 | 728 | | |
722 | 729 | | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
723 | 735 | | |
724 | 736 | | |
725 | 737 | | |
| |||
815 | 827 | | |
816 | 828 | | |
817 | 829 | | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
818 | 835 | | |
819 | 836 | | |
820 | 837 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | | - | |
| 480 | + | |
| 481 | + | |
481 | 482 | | |
482 | 483 | | |
483 | 484 | | |
484 | 485 | | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
485 | 491 | | |
486 | 492 | | |
487 | 493 | | |
| |||
615 | 621 | | |
616 | 622 | | |
617 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
618 | 633 | | |
619 | 634 | | |
620 | 635 | | |
| |||
644 | 659 | | |
645 | 660 | | |
646 | 661 | | |
647 | | - | |
648 | | - | |
649 | 662 | | |
650 | 663 | | |
651 | 664 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1177 | 1177 | | |
1178 | 1178 | | |
1179 | 1179 | | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
1180 | 1196 | | |
1181 | 1197 | | |
1182 | 1198 | | |
| |||
0 commit comments