root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.64k stars 1.26k forks source link

Python class inherited from a ROOT class fails in last release #16520

Open PPaye opened 1 week ago

PPaye commented 1 week ago

Check duplicate issues.

Description

Inherit whatever ROOT parent class in a python class generates error on the TObject::DoError method. Python raises an error on TypeError. Which is categorical wrong, it should be NotImplemented.

At the root-forum it is being suggested that RDataFrame is not a class to be inherited in PyRoot; due to "composition over inheritance" idiom and warnings on bad data type manipulation internally leading to wrong numerical results. Is this going to be for all ROOT classes? No ROOT class should be inherited in a Python class from now on ?

It only affects the last release 6.32.04 and 6.32.06 Release 6.30.02 works fine.

Similar issues: https://github.com/root-project/root/issues/12391 https://root-forum.cern.ch/t/rdataframe-has-no-virtual-destructor/53605 https://root-forum.cern.ch/t/typeerror-no-python-side-overrides-supported-failed-to-compile-the-dispatcher-code/53198/14

Reproducer

from ROOT import TObject

class C(TObject):
    def __init__(self):
        super().__init__()  # Initialize the base class

    def some_method(self):
        print("This is a method in class C.")
  In [1]: from ROOT import TObject
        ...: 
        ...: class C(TObject):
        ...:     def __init__(self):
        ...:         super().__init__()  # Call the constructor of TObject
        ...: 
Installed ROOT event loop hook.
input_line_35:10:62: error: unknown type name '__va_list_tag'
  void DoError(int arg0, const char* arg1, const char* arg2, __va_list_tag[1] arg3) const {
                                                             ^
input_line_35:10:79: error: expected ')'
  void DoError(int arg0, const char* arg1, const char* arg2, __va_list_tag[1] arg3) const {
                                                                              ^
input_line_35:10:15: note: to match this '('
  void DoError(int arg0, const char* arg1, const char* arg2, __va_list_tag[1] arg3) const {
              ^
input_line_35:11:47: error: use of undeclared identifier 'arg3'
    return TObject::DoError(arg0, arg1, arg2, arg3);
                                              ^
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 3
      1 from ROOT import TObject
----> 3 class C(TObject):
      4     def __init__(self):
      5         super().__init__()  # Call the constructor of TObject

TypeError: no python-side overrides supported (failed to compile the dispatcher code)

ROOT version

ROOT Version: 6.32.02 Built for linuxx8664gcc on Jun 18 2024, 04:46:14 From tags/v6-32-02@v6-32-02

ROOT Version: 6.32.06 Built for linuxx8664gcc on Sep 21 2024, 19:19:59 From tags/v6-32-06@v6-32-06

Installation method

pre-built binary

Operating system

Linux, Ubuntu 23

Additional context

No response

vepadulano commented 1 week ago

Dear @PPaye ,

Thanks for reaching out to us! At a first glance, I would say this is a degradation and we should try to understand why that happened, generally speaking.

But please note the following:

At the root-forum it is being suggested that RDataFrame is not a class to be inherited in PyRoot;

The answer on the ROOT forum does not say that RDataFrame should not be inherited-from in a Python class. It should not be inherited-from in general. The class explicitly does not provide a virtual destructor, so virtual inheritance would not work even in C++. This is part of the class design and it is not related to this issue with Python.