|
7 | 7 | # For the licensing terms see $ROOTSYS/LICENSE. # |
8 | 8 | # For the list of contributors see $ROOTSYS/README/CREDITS. # |
9 | 9 | ################################################################################ |
| 10 | + |
| 11 | +import functools |
| 12 | + |
10 | 13 | from . import pythonization |
11 | 14 |
|
12 | | -def _TColor_constructor(self, *args, **kwargs): |
| 15 | + |
| 16 | +def _tcolor_constructor(original_init): |
13 | 17 | """ |
14 | | - Forward the arguments to the C++ constructor and retain ownership. This |
15 | | - helps avoiding double deletes due to ROOT automatic memory management. |
| 18 | + Wrapper for TColor constructor that retains ownership to avoid double deletes. |
| 19 | + Uses functools.wraps to preserve the original function's attributes. |
16 | 20 | """ |
17 | | - self._cpp_constructor(*args, **kwargs) |
18 | | - import ROOT |
19 | | - ROOT.SetOwnership(self, False) |
| 21 | + @functools.wraps(original_init) |
| 22 | + def wrapper(self, *args, **kwargs): |
| 23 | + """ |
| 24 | + Forward the arguments to the C++ constructor and retain ownership. This |
| 25 | + helps avoiding double deletes due to ROOT automatic memory management. |
| 26 | + """ |
| 27 | + original_init(self, *args, **kwargs) |
| 28 | + import ROOT |
| 29 | + ROOT.SetOwnership(self, False) |
| 30 | + return wrapper |
20 | 31 |
|
21 | 32 |
|
22 | 33 | @pythonization("TColor") |
23 | 34 | def pythonize_tcolor(klass): |
24 | | - klass._cpp_constructor = klass.__init__ |
25 | | - klass.__init__ = _TColor_constructor |
| 35 | + klass.__init__ = _tcolor_constructor(klass.__init__) |
| 36 | + |
0 commit comments