Skip to content

[v638] Backport recent Python interface fixes#21784

Merged
guitargeek merged 2 commits intoroot-project:v6-38-00-patchesfrom
guitargeek:bp_1
Apr 3, 2026
Merged

[v638] Backport recent Python interface fixes#21784
guitargeek merged 2 commits intoroot-project:v6-38-00-patchesfrom
guitargeek:bp_1

Conversation

@guitargeek
Copy link
Copy Markdown
Contributor

A unit test covering the reported issue is also implemented.

Closes root-project#21732

(cherry picked from commit de992f1)
Introduce a Python-side adapter (**TDirectoryPythonAdapter**) to
implement the expected lazy semantics of gDirectory, analogous to
`ROOT::Internal::TDirectoryAtomicAdapter` on the C++ side.

In C++, `gDirectory` is defined as a macro expanding to a temporary adapter
object that implicitly converts to the current `TDirectory*`. This relies on
implicit conversions, operator overloading, preprocessor tricks, and
pretending to ROOT meta that the type of `gDirectory` is a functor
returning a `TDirectory*` that cannot be faithfully represented in
Python bindings. This results in problems like root-project#21693, which shows that
the coupling between these hacks and cppyy conversion is very brittle.

The new TDirectoryPythonAdapter restores the intended semantics by:
  * Resolving the current directory lazily on every attribute access
  * Forwarding attribute access, string representation, truthiness, and
    equality comparisons to the current TDirectory

Note that identity comparisons (`is`) are no longer meaningful for
gDirectory, as it represents a dynamic proxy rather than a stable
object. Tests are updated to use equality (`==`), matching the C++
adapter semantics, reverting a change that was only made recently.

Assignment semantics (`gDirectory = ...`) are intentionally not
supported, as Python does not provide a mechanism equivalent to C++
operator= on proxy objects without introducing fragile or intrusive
behavior.

Closes root-project#21693.

A unit test covering the reproducer for that issue is also implemented.

(cherry picked from commit 2659fe3)
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Test Results

    19 files      19 suites   2d 21h 28m 56s ⏱️
 3 715 tests  3 715 ✅ 0 💤 0 ❌
68 846 runs  68 846 ✅ 0 💤 0 ❌

Results for commit 0bce91a.

@guitargeek guitargeek merged commit 63aae0c into root-project:v6-38-00-patches Apr 3, 2026
25 of 29 checks passed
@guitargeek guitargeek deleted the bp_1 branch April 3, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant