Skip to content

[PyROOT] Get names and types of all overloads' signature #9138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vepadulano
Copy link
Member

@vepadulano vepadulano commented Oct 18, 2021

This PR introduces a machinery to get the names and types (separately) of the signature of each overload of a particular CPPOverload object. This allows for example for something like.

EDIT

Here is the latest status of this feature after some discussion:

>>> import ROOT
>>> ROOT.gInterpreter.Declare("""
 int foo(int a, float b);
 int foo(int a);
 float foo(float b);
 double foo(int a, float b, double c);
... """)
True
>>> ROOT.foo
<cppyy.CPPOverload object at 0x7fc470789fd0>
>>> from pprint import pprint
>>> pprint(ROOT.foo.func_overloads_names)
{'double ::foo(int a, float b, double c)': ('a', 'b', 'c'),
 'float ::foo(float b)': ('b',),
 'int ::foo(int a)': ('a',),
 'int ::foo(int a, float b)': ('a', 'b')}
>>> pprint(ROOT.foo.func_overloads_types)
{'double ::foo(int a, float b, double c)': {'input_types': ('int',
                                                            'float',
                                                            'double'),
                                            'return_type': 'double'},
 'float ::foo(float b)': {'input_types': ('float',), 'return_type': 'float'},
 'int ::foo(int a)': {'input_types': ('int',), 'return_type': 'int'},
 'int ::foo(int a, float b)': {'input_types': ('int', 'float'),
                               'return_type': 'int'}}

@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link

Build failed on mac11.0/cxx17.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2021-10-18T17:44:04.405Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:26:23: warning: 'GetSignature' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.405Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:29:23: warning: 'GetPrototype' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.405Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:30:23: warning: 'GetPriority' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.406Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:31:18: warning: 'IsGreedy' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.406Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:33:23: warning: 'GetMaxArgs' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.406Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:34:23: warning: 'GetCoVarNames' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.406Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:35:23: warning: 'GetArgDefault' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.406Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:36:23: warning: 'GetScopeProxy' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.406Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:37:35: warning: 'GetFunctionAddress' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:44:04.406Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:39:25: warning: 'Clone' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]

And 212 more

Failing tests:

@phsft-bot
Copy link

Build failed on mac1014/python3.
Running on macitois22.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Warnings:

  • [2021-10-18T17:43:31.343Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:26:23: warning: 'GetSignature' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.343Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:29:23: warning: 'GetPrototype' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.602Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:30:23: warning: 'GetPriority' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.602Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:31:18: warning: 'IsGreedy' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.602Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:33:23: warning: 'GetMaxArgs' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.602Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:34:23: warning: 'GetCoVarNames' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.602Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:35:23: warning: 'GetArgDefault' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.602Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:36:23: warning: 'GetScopeProxy' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.602Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:37:35: warning: 'GetFunctionAddress' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  • [2021-10-18T17:43:31.603Z] /Volumes/HD2/build/workspace/root-pullrequests-build/root/bindings/pyroot/cppyy/CPyCppyy/src/CPPMethod.h:39:25: warning: 'Clone' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]

And 101 more

@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link

Build failed on mac11.0/cxx17.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@eguiraud eguiraud removed their request for review August 18, 2022 17:32
@vepadulano vepadulano force-pushed the cppyy-signature-names-types branch from 8e3e5e8 to db26d41 Compare August 30, 2022 13:44
@phsft-bot
Copy link

Starting build on ROOT-debian10-i386/soversion, ROOT-performance-centos8-multicore/cxx17, ROOT-ubuntu18.04/nortcxxmod, ROOT-ubuntu2004/python3, mac1015/cxx17, mac11/cxx14, windows10/cxx14
How to customize builds

@vepadulano
Copy link
Member Author

A clear use case for this functionality has not surfaced since the opening of the PR. This can be closed now, to be reopened in case it becomes necessary.

@siliataider
Copy link
Contributor

Reopening and bringing this up to date, a clear use case has surfaced in fact: #19437

@siliataider siliataider reopened this Jul 23, 2025
@siliataider siliataider requested a review from dpiparo as a code owner July 23, 2025 08:49
@siliataider siliataider force-pushed the cppyy-signature-names-types branch from db26d41 to d6f02d8 Compare July 23, 2025 09:13
Copy link

github-actions bot commented Jul 23, 2025

Test Results

    21 files      21 suites   3d 5h 1m 30s ⏱️
 3 218 tests  3 214 ✅ 0 💤 4 ❌
65 859 runs  65 855 ✅ 0 💤 4 ❌

For more details on these failures, see this check.

Results for commit 9f6b3d1.

♻️ This comment has been updated with latest results.

@siliataider siliataider force-pushed the cppyy-signature-names-types branch 5 times, most recently from cbe56ee to 26818b5 Compare July 24, 2025 16:03
@siliataider siliataider self-assigned this Jul 25, 2025
@siliataider
Copy link
Contributor

We should be able to merge this now, @vepadulano ?

@vepadulano
Copy link
Member Author

We should be able to merge this now, @vepadulano ?

Yes, but given it's my own PR I can't approve it. Let's ask @guitargeek for an approval. This is in the context of RDF Pythonizations. It may be that this code is not going to be necessary once we have a CppInterop-based CPyCppyy, but currently we need it.

@siliataider siliataider requested a review from guitargeek July 25, 2025 09:24
Copy link
Contributor

@guitargeek guitargeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much @siliataider!

Could you please just revert the unrelated code formatting changes in CPPOverload.cxx? CPyCppyy has its own code style incompatible with the one of ROOT, and it would be better to not do unnecessary formatting changes in a codebase that is already hard to keep in sync.

@siliataider siliataider force-pushed the cppyy-signature-names-types branch 3 times, most recently from dd6615e to d0716bb Compare July 25, 2025 10:05
@siliataider siliataider requested a review from guitargeek July 25, 2025 10:07
Expose two new attributes of a CPPOverload object on the Python side,
namely `func_overloads_names` and `func_overloads_types`. The first
returns a dictionary with all the input parameter names for all the
overloads, the second returns a dictionary with the types of the return
and input parameters for all the overloads. An example:

```python
import ROOT
from pprint import pprint

ROOT.gInterpreter.Declare("""
 int foo(int a, float b);
 int foo(int a);
 float foo(float b);
 double foo(int a, float b, double c);
""")

pprint(ROOT.foo.func_overloads_names)
pprint(ROOT.foo.func_overloads_types)
```
Output:
```
{'double ::foo(int a, float b, double c)': ('a', 'b', 'c'),
 'float ::foo(float b)': ('b',),
 'int ::foo(int a)': ('a',),
 'int ::foo(int a, float b)': ('a', 'b')}
{'double ::foo(int a, float b, double c)': {'input_types': ('int',
                                                            'float',
                                                            'double'),
                                            'return_type': 'double'},
 'float ::foo(float b)': {'input_types': ('float',), 'return_type': 'float'},
 'int ::foo(int a)': {'input_types': ('int',), 'return_type': 'int'},
 'int ::foo(int a, float b)': {'input_types': ('int', 'float'),
                               'return_type': 'int'}}
```
@siliataider siliataider force-pushed the cppyy-signature-names-types branch from d0716bb to b3d0f9b Compare July 25, 2025 11:06
@siliataider siliataider force-pushed the cppyy-signature-names-types branch from b3d0f9b to 9f6b3d1 Compare July 25, 2025 11:10
Copy link
Contributor

@guitargeek guitargeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you very much Vincenzo and Silia.

Make sure that you quickly integrate some pythonizations that use these new functions, so that we have some coverage and make sure this functionality is not broken in the future, e.g. by the upcoming cppyy upgrade.

@siliataider siliataider merged commit 54c8207 into root-project:master Jul 25, 2025
43 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants