From a23610d6c63da9893e05b5f630afe92224e406cd Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Wed, 12 Jun 2024 18:59:58 -0400 Subject: [PATCH 1/3] add tests/test_1229_const_in_typename.py --- tests/test_1229_const_in_typename.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/test_1229_const_in_typename.py diff --git a/tests/test_1229_const_in_typename.py b/tests/test_1229_const_in_typename.py new file mode 100644 index 000000000..304f5ffeb --- /dev/null +++ b/tests/test_1229_const_in_typename.py @@ -0,0 +1,22 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE + +import pytest +import skhep_testdata + +import uproot + + +@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*' From 72076e2c169aefe21dab8225d650555c0f7bf005 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Wed, 12 Jun 2024 19:44:36 -0400 Subject: [PATCH 2/3] tests/test_1229_const_in_typename.py: test without a file --- tests/test_1229_const_in_typename.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/tests/test_1229_const_in_typename.py b/tests/test_1229_const_in_typename.py index 304f5ffeb..ac1085c7c 100644 --- a/tests/test_1229_const_in_typename.py +++ b/tests/test_1229_const_in_typename.py @@ -3,20 +3,11 @@ import pytest import skhep_testdata -import uproot +from uproot.containers import AsPointer +from uproot.interpretation.identify import parse_typename +from uproot.models.TH import Model_TH1I -@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_in_typename(): + assert parse_typename("TH1I*") == AsPointer(Model_TH1I) + assert parse_typename("const TH1I*") == AsPointer(Model_TH1I) From 75d950bbe5e08417443975081bff877913c7088b Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Wed, 12 Jun 2024 19:38:26 -0400 Subject: [PATCH 3/3] ignore the const token --- src/uproot/interpretation/identify.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uproot/interpretation/identify.py b/src/uproot/interpretation/identify.py index 26daafbd9..d6724e967 100644 --- a/src/uproot/interpretation/identify.py +++ b/src/uproot/interpretation/identify.py @@ -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":