Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support const in typename #1231

Merged
merged 8 commits into from
Jan 17, 2025
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
27 changes: 2 additions & 25 deletions src/uproot/interpretation/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header):
if tokens[i].group(0) == ",":
_parse_error(tokens[i].start() + 1, typename, file)

elif tokens[i].group(0) == "const":
return _parse_node(tokens, i + 1, typename, file, quote, header, inner_header)
elif tokens[i].group(0) == "Bool_t":
return i + 1, _parse_maybe_quote('numpy.dtype("?")', quote)
elif tokens[i].group(0) == "bool":
Expand Down Expand Up @@ -919,19 +921,6 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header):
_parse_maybe_quote(f"uproot.containers.AsString({header})", quote),
)

elif (
has2
and tokens[i].group(0) == "const"
and (
tokens[i + 1].group(0) == "string"
or _simplify_token(tokens[i + 1]) == "std::string"
)
):
return (
i + 2,
_parse_maybe_quote(f"uproot.containers.AsString({header})", quote),
)

elif tokens[i].group(0) == "TString":
return (
i + 1,
Expand All @@ -947,18 +936,6 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header):
quote,
),
)
elif (
has2
and tokens[i].group(0) == "const"
and _simplify_token(tokens[i + 1]) == "char*"
):
return (
i + 2,
_parse_maybe_quote(
"uproot.containers.AsString(False, length_bytes='4', typename='char*')",
quote,
),
)

elif tokens[i].group(0) == "bitset" or _simplify_token(tokens[i]) == "std::bitset":
_parse_expect("<", tokens, i + 1, typename, file)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_1229_const_in_typename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import pytest
import skhep_testdata

import uproot
from uproot.interpretation.identify import parse_typename


@pytest.fixture(scope="module")
def datafile(tmpdir_factory):
yield skhep_testdata.data_path("uproot-issue-1229.root")


@pytest.fixture
def tree(datafile):
with uproot.open(datafile) as f:
yield f["tree"]


def test_const_in_typename(tree):
assert tree["branch/pointer"].typename == "TFooMember*"
assert tree["branch/const_pointer"].typename == "TFooMember*"


def test_const_parse_typename():
assert parse_typename("TH1I*") == parse_typename("const TH1I*")
Loading