Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README/ReleaseNotes/v638/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ If you want to keep using `TList*` return values, you can write a small adapter

ROOT dropped support for Python 3.8, meaning ROOT now requires at least Python 3.9.

### Deprecation of the `TObject` equality pythonization

`TObject.__eq__` is deprecated and will be removed in ROOT 6.40.

It forwards to `TObject::Equals()`, which uses pointer comparison if not overridden in derived classes.
This may be confusing, because people expect value comparisons.
Use Pythons `is` for pointer comparison, or request an implementation of `operator==` on the C++ side if you need value-based equality checks for a given class.

### Deprecate the attribute pythonization of `TDirectory` in favor of item-getting syntax

Since ROOT 6.32, the recommended way to get objects from a `TFile` or any `TDirectory` in general is via `__getitem__`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

def _TFileOpen(klass, *args):

import ROOT

Check failure on line 84 in bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tfile.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tfile.py:84:12: F401 `ROOT` imported but unused

# Redefinition of ROOT.TFile.Open(str, ...):
# check if the instance of TFile is a C++ nullptr and raise a
Expand All @@ -90,7 +90,7 @@
# klass: TFile class
# *args: arguments passed to the constructor
f = klass._OriginalOpen(*args)
if f == ROOT.bind_object(0, klass):
if not f:
# args[0] can be either a string or a TFileOpenHandle
raise OSError('Failed to open file {}'.format(str(args[0])))
return f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
# For the list of contributors see $ROOTSYS/README/CREDITS. #
################################################################################

from ROOT.libROOTPythonizations import AddTObjectEqNePyz
import cppyy

Check failure on line 12 in bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tobject.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tobject.py:11:1: I001 Import block is un-sorted or un-formatted

# Searching


def _contains(self, o):
# Relies on TObject::FindObject
# Parameters:
Expand All @@ -22,26 +23,47 @@
# - True if self contains o
return bool(self.FindObject(o))


# Comparison operators


def _eq(self, o):
import warnings

warnings.warn(
"\nTObject.__eq__ is deprecated and will be removed in ROOT 6.40."
"\n\nIt forwards to TObject::Equals(), which uses pointer comparison if"
" not overridden in derived classes."
"\nThis may be confusing, because people expect value comparisons."
"\nUse Pythons `is` for pointer comparison, or request/implement"
" `operator==` on the C++ side if you need value-based equality checks.",
FutureWarning,
stacklevel=2,
)
return self._cpp_eq(o)


def _lt(self, o):
if isinstance(o, cppyy.gbl.TObject):
return self.Compare(o) == -1
else:
return NotImplemented


def _le(self, o):
if isinstance(o, cppyy.gbl.TObject):
return self.Compare(o) <= 0
else:
return NotImplemented


def _gt(self, o):
if isinstance(o, cppyy.gbl.TObject):
return self.Compare(o) == 1
else:
return NotImplemented


def _ge(self, o):
if isinstance(o, cppyy.gbl.TObject):
return self.Compare(o) >= 0
Expand All @@ -57,11 +79,14 @@

# Inject comparison operators
AddTObjectEqNePyz(klass)
klass._cpp_eq = klass.__eq__
klass.__eq__ = _eq
klass.__lt__ = _lt
klass.__le__ = _le
klass.__gt__ = _gt
klass.__ge__ = _ge


# Instant pythonization (executed at `import ROOT` time), no need of a
# decorator. This is a core class that is instantiated before cppyy's
# pythonization machinery is in place.
Expand Down
12 changes: 3 additions & 9 deletions main/python/cmdLineUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python/22434262#22434262
# Thanks J.F. Sebastian !!

from contextlib import contextmanager
import os
import sys
from time import sleep

Check failure on line 19 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

main/python/cmdLineUtils.py:19:18: F401 `time.sleep` imported but unused
from itertools import zip_longest

Check failure on line 20 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

main/python/cmdLineUtils.py:20:23: F401 `itertools.zip_longest` imported but unused

Check failure on line 20 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

main/python/cmdLineUtils.py:16:1: I001 Import block is un-sorted or un-formatted

def fileno(file_or_fd):
"""
Expand Down Expand Up @@ -81,10 +81,10 @@
ROOT.PyConfig.IgnoreCommandLineOptions = True
ROOT.gROOT.GetVersion()

import argparse

Check failure on line 84 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E402)

main/python/cmdLineUtils.py:84:1: E402 Module level import not at top of file
import glob

Check failure on line 85 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E402)

main/python/cmdLineUtils.py:85:1: E402 Module level import not at top of file
import fnmatch

Check failure on line 86 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E402)

main/python/cmdLineUtils.py:86:1: E402 Module level import not at top of file
import logging

Check failure on line 87 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E402)

main/python/cmdLineUtils.py:87:1: E402 Module level import not at top of file

Check failure on line 87 in main/python/cmdLineUtils.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

main/python/cmdLineUtils.py:84:1: I001 Import block is un-sorted or un-formatted

LOG_FORMAT = "%(levelname)s: %(message)s"
logging.basicConfig(format=LOG_FORMAT)
Expand Down Expand Up @@ -195,11 +195,9 @@
"""
Return True if the object, corresponding to the key, inherits from TDirectory
"""
import cppyy

classname = key.GetClassName()
cl = ROOT.gROOT.GetClass(classname)
if cl == cppyy.nullptr:
if not cl:
logging.warning("Unknown class to ROOT: " + classname)
return False
return cl.InheritsFrom(ROOT.TDirectory.Class())
Expand All @@ -209,11 +207,9 @@
"""
Return True if the object, corresponding to the key, inherits from TTree
"""
import cppyy

classname = key.GetClassName()
cl = ROOT.gROOT.GetClass(classname)
if cl == cppyy.nullptr:
if not cl:
logging.warning("Unknown class to ROOT: " + classname)
return False
return cl.InheritsFrom(ROOT.TTree.Class())
Expand All @@ -223,11 +219,9 @@
"""
Return True if the object, corresponding to the key, inherits from THnSparse
"""
import cppyy

classname = key.GetClassName()
cl = ROOT.gROOT.GetClass(classname)
if cl == cppyy.nullptr:
if not cl:
logging.warning("Unknown class to ROOT: " + classname)
return False
return cl.InheritsFrom(ROOT.THnSparse.Class())
Expand Down
Loading