Skip to content

Commit c3acd75

Browse files
committed
Fixed RNTuple tree structure and minor refactoring
1 parent 044e974 commit c3acd75

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/uproot_browser/tree.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import dataclasses
88
import functools
9-
from collections.abc import Mapping
9+
from collections.abc import Iterable
1010
from pathlib import Path
11-
from typing import Any, Literal, TypedDict
11+
from typing import Any, Literal, Protocol, TypedDict
1212

1313
import uproot
1414
import uproot.reading
@@ -29,6 +29,10 @@
2929
)
3030

3131

32+
class SupportsRecursiveKeys(Protocol):
33+
def keys(self, recursive: bool = True) -> Iterable[str]: ...
34+
35+
3236
def __dir__() -> tuple[str, ...]:
3337
return __all__
3438

@@ -53,21 +57,14 @@ def _(item: uproot.reading.ReadOnlyDirectory) -> Literal[True]: # noqa: ARG001
5357

5458

5559
@is_dir.register
56-
def _(item: uproot.behaviors.TBranch.HasBranches) -> bool:
57-
return len(item.branches) > 0
58-
59-
60-
@is_dir.register
61-
def _(item: uproot.behaviors.RNTuple.HasFields) -> bool:
62-
return len(item.keys()) > 0
60+
def _(
61+
item: uproot.behaviors.TBranch.HasBranches | uproot.behaviors.RNTuple.HasFields,
62+
) -> bool:
63+
return len(item) > 0
6364

6465

65-
def get_children(item: Mapping[str, Any]) -> set[str]:
66-
return {
67-
key.split(";")[0]
68-
for key in item.keys() # noqa: SIM118
69-
if "/" not in key
70-
}
66+
def get_children(item: SupportsRecursiveKeys) -> set[str]:
67+
return {key.split(";")[0] for key in item.keys(recursive=False)}
7168

7269

7370
@dataclasses.dataclass

0 commit comments

Comments
 (0)