Skip to content
Next Next commit
Revert "[PyROOT] Forward compatibility of pretty printing with CPyCppyy"
This reverts commit d5efd70.

We are patching the automatic conversion to Python strings back in, so
it's not necessary to Pythonize a `__str__` funciton implementing it in
C++.

Also, the `hasattr(foo, "___cpp__str")` caused a *huge* performance it
in some cases, because looking up a non-existing attribute in cppyy can
be quite expensive. All base classes are crawled too, and that invokes
the interpreter and string manipulation.
  • Loading branch information
guitargeek committed Mar 18, 2024
commit 0175a528a1a51aab90f47fab0156224ad421572e
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,8 @@ def pythonize_generic(klass, name):
# Add pretty printing via setting the __str__ special function

# Exclude classes which have the method __str__ already defined in C++
# Since version 1.12.11, CPyCppyy is internally renaming any direct C++
# __str__ attribute to __cpp_str and replaces __str__ with a pythonic
# wrapper. Therefore, the "CPPOverload" name check below doesn't work
# anymore with that version. Fortunately, we can just check if the
# __cpp_str attribute exists instead. Still, this code does both checks for
# maximum compatibility.
m = getattr(klass, '__str__', None)
has_cpp_str = type(m).__name__ == "CPPOverload" or hasattr(klass, "__cpp_str")
has_cpp_str = True if m is not None and type(m).__name__ == 'CPPOverload' else False

# Exclude std::string with its own pythonization from cppyy
exclude = [ 'std::string' ]
Expand Down