From f02b67e675a811d629ab92b0ba4fc86f0197e7e9 Mon Sep 17 00:00:00 2001 From: Nikolai Hartmann Date: Tue, 17 Sep 2024 12:27:57 +0200 Subject: [PATCH] treat more cases for typename --- .../interpretation/known_forth/__init__.py | 19 +++++++++++++++---- src/uproot/interpretation/objects.py | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/uproot/interpretation/known_forth/__init__.py b/src/uproot/interpretation/known_forth/__init__.py index b3b0a5ae9..35638b53b 100644 --- a/src/uproot/interpretation/known_forth/__init__.py +++ b/src/uproot/interpretation/known_forth/__init__.py @@ -5,6 +5,7 @@ """ from __future__ import annotations +import uproot from uproot.interpretation.known_forth.atlas.element_link import VectorVectorElementLink KNOWN_FORTH_DICT = { @@ -20,10 +21,20 @@ def known_forth_of(model): - if not hasattr(model, "typename"): - return - - typename = model.typename + """ + Args: + model: The :doc:`uproot.model.Model` to look up known forth for + + Returns an object with attributes `forth_code` and `awkward_form` if a known + special case exists, else None + """ + try: + typename = model.typename + except AttributeError: + try: + typename = model.classname + except AttributeError: + typename = uproot.model.classname_decode(model.__name__) if typename not in KNOWN_FORTH_DICT: return diff --git a/src/uproot/interpretation/objects.py b/src/uproot/interpretation/objects.py index 7db93886a..37306a135 100644 --- a/src/uproot/interpretation/objects.py +++ b/src/uproot/interpretation/objects.py @@ -47,7 +47,8 @@ class AsObjects(uproot.interpretation.Interpretation): replace this interpretation with a faster-to-read equivalent, but not all data types can be simplified. - # TODO: known_forth can define forth code and forms for special cases that will be picked up here as well + :doc:`uproot.interpretation.known_forth` defines forth code and forms for + special cases that will be picked up here as well """ def __init__(self, model, branch=None):