Skip to content

Commit 3383f42

Browse files
aviralgarg05guitargeek
authored andcommitted
[Python] Preserve __init__ metadata using functools.wraps
This fixes the Jupyter TColor.DefinedColors behavior. Closes #20018.
1 parent 06bd32f commit 3383f42

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

  • bindings/pyroot/pythonizations/python/ROOT/_pythonization

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tcolor.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77
# For the licensing terms see $ROOTSYS/LICENSE. #
88
# For the list of contributors see $ROOTSYS/README/CREDITS. #
99
################################################################################
10+
11+
import functools
12+
1013
from . import pythonization
1114

1215

13-
def _TColor_constructor(self, *args, **kwargs):
14-
"""
15-
Forward the arguments to the C++ constructor and retain ownership. This
16-
helps avoiding double deletes due to ROOT automatic memory management.
17-
"""
18-
self._cpp_constructor(*args, **kwargs)
19-
import ROOT
20-
ROOT.SetOwnership(self, False)
16+
def _tcolor_constructor(original_init):
17+
@functools.wraps(original_init)
18+
def wrapper(self, *args, **kwargs):
19+
original_init(self, *args, **kwargs)
20+
import ROOT
21+
22+
ROOT.SetOwnership(self, False)
23+
24+
return wrapper
2125

2226

2327
@pythonization("TColor")
2428
def pythonize_tcolor(klass):
25-
klass._cpp_constructor = klass.__init__
26-
klass.__init__ = _TColor_constructor
29+
klass.__init__ = _tcolor_constructor(klass.__init__)

0 commit comments

Comments
 (0)