[python] Improve CPyCppyy heuristic for Clone methods #18423
Merged
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.
The heuristic checks if the token "Clone" is present in the method name being called and gives Python the ownership of the returned object. This is valid behaviour for methods such as
TObject::Clone
where the ownership of the returned value is given to the caller. But theCPPOverload::Set
method gets as the method name being called the actual function name concatenated with the full template argument list. For example, given the functionWhen it passes through this method its name will be
foo<T>
. This behaviour has an undesired side-effect. WhenT
is a type with the tokenClone
in its name, then the heuristic will trigger and Python will take ownership of the return value. This is the root cause of the problem seen at #16725, whereT
isTClonesArray
.This commit improves on the heuristic by stripping the template argument list from the method name before checking for the presence of the token.
Fixes #16725
Hopefully supersedes #18416