Skip to content

Commit 7b0f726

Browse files
committed
[Python] Use cppyy.types module instead of private cppyy._backend
Do what @wlav suggested in #20287 (comment).
1 parent ee8c8d3 commit 7b0f726

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

bindings/pyroot/pythonizations/python/ROOT/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from . import _asan
3333

3434
import cppyy
35+
import cppyy.types
3536

3637
# Build cache of commonly used python strings (the cache is python intern, so
3738
# all strings are shared python-wide, not just in PyROOT).
@@ -111,7 +112,7 @@ def _can_be_module(obj) -> bool:
111112
import types
112113

113114

114-
def _lookup_root_module(fullname: str) -> Optional[Union[types.ModuleType, cppyy._backend.CPPScope]]:
115+
def _lookup_root_module(fullname: str) -> Optional[Union[types.ModuleType, cppyy.types.Scope]]:
115116
"""
116117
Recursively looks up attributes of the ROOT facade, using a full module
117118
name, and return it if it can be used as a ROOT submodule. This is the case

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,12 @@ def _get_cpp_signature(func, rdf, cols):
321321
Gets the C++ signature of a cppyy callable.
322322
"""
323323
import cppyy
324+
import cppyy.types
324325

325-
if isinstance(func, cppyy._backend.TemplateProxy):
326+
if isinstance(func, cppyy.types.Template):
326327
func = get_cpp_overload_from_templ_proxy(func, get_column_types(rdf, cols))
327328

328-
if not isinstance(func, cppyy._backend.CPPOverload):
329+
if not isinstance(func, cppyy.types.Function):
329330
raise TypeError(f"Expected a cppyy callable, got {type(func).__name__}")
330331

331332
overload_types = func.func_overloads_types
@@ -338,8 +339,9 @@ def _to_std_function(func, rdf, cols):
338339
Converts a cppyy callable to std::function.
339340
"""
340341
import cppyy
342+
import cppyy.types
341343

342-
if not isinstance(func, cppyy._backend.CPPOverload) and not isinstance(func, cppyy._backend.TemplateProxy):
344+
if not isinstance(func, cppyy.types.Function) and not isinstance(func, cppyy.types.Template):
343345
raise TypeError(f"Expected a cppyy callable, got {type(func).__name__}")
344346

345347
signature = _get_cpp_signature(func, rdf, cols)
@@ -373,10 +375,11 @@ def _handle_cpp_callables(func, original_template, *args, rdf=None, cols=None):
373375
"""
374376

375377
import cppyy
378+
import cppyy.types
376379

377-
is_cpp_functor = lambda: isinstance(getattr(func, "__call__", None), cppyy._backend.CPPOverload) # noqa E731
380+
is_cpp_functor = lambda: isinstance(getattr(func, "__call__", None), cppyy.types.Function) # noqa E731
378381

379-
is_std_function = lambda: isinstance(getattr(func, "target_type", None), cppyy._backend.CPPOverload) # noqa E731
382+
is_std_function = lambda: isinstance(getattr(func, "target_type", None), cppyy.types.Function) # noqa E731
380383

381384
# handle free functions
382385
if callable(func) and not is_cpp_functor() and not is_std_function():

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_roofit/_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ def getter(k, v):
2424
# We have to use ROOT here and not cppy.gbl, because the RooFit namespace is pythonized itself.
2525
import ROOT
2626
import cppyy
27+
import cppyy.types
2728

2829
func = getattr(ROOT.RooFit, k)
2930

30-
if isinstance(func, cppyy._backend.CPPOverload):
31+
if isinstance(func, cppyy.types.Function):
3132
# Pythonization for functions that don't pass any RooCmdArgs like ShiftToZero() and MoveToBack(). For Eg,
3233
# Default bindings: pdf.plotOn(frame, ROOT.RooFit.MoveToBack())
3334
# With pythonizations: pdf.plotOn(frame, MoveToBack=True)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,12 @@ def _SetBranchAddress(self, bname, addr, *args, **kwargs):
254254
```
255255
"""
256256
import cppyy
257+
import cppyy.types
257258

258259
branch = self.GetBranch(bname)
259260

260261
# Pythonization for cppyy proxies (of type CPPInstance)
261-
if isinstance(addr, cppyy._backend.CPPInstance):
262+
if isinstance(addr, cppyy.types.Instance):
262263
addr = _pythonize_branch_addr(branch, addr)
263264

264265
# Figure out data_type in case addr is a numpy.ndarray or array.array

roottest/python/basic/PyROOT_datatypetest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def setup_class(cls):
3737
cls.datatypes = cppyy.load_reflection_info(cls.test_dct)
3838
cls.N = cppyy.gbl.N
3939
# In new Cppyy, nullptr can't be found in gbl.
40-
cls.nullptr = cppyy._backend.nullptr
40+
cls.nullptr = cppyy.nullptr
4141

4242
def test01_load_reflection_cache(self):
4343
"""Loading reflection info twice should result in the same object"""

roottest/python/basic/PyROOT_datatypetest_numpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def setup_class(cls):
3737
cls.datatypes = cppyy.load_reflection_info(cls.test_dct)
3838
cls.N = cppyy.gbl.N
3939
# In new Cppyy, nullptr can't be found in gbl.
40-
cls.nullptr = cppyy._backend.nullptr
40+
cls.nullptr = cppyy.nullptr
4141

4242
def test01_buffer_to_numpy(self):
4343
"""Wrap buffer with NumPy array"""

0 commit comments

Comments
 (0)