Skip to content

Commit

Permalink
_has_refs directly in Ref
Browse files Browse the repository at this point in the history
  • Loading branch information
giadarol committed Feb 26, 2022
1 parent 1252543 commit 8f6d524
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions xobjects/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
default_conf,
)
from .scalar import Int64, is_scalar
import xobjects as xo

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -215,9 +214,8 @@ def __new__(cls, name, bases, data):

# determine has_refs
if '_itemtype' in data.keys():
if ((hasattr(data['_itemtype'], '_has_refs')
and data['_itemtype']._has_refs)
or isinstance(data['_itemtype'], xo.Ref)):
if (hasattr(data['_itemtype'], '_has_refs')
and data['_itemtype']._has_refs):
data['_has_refs'] = True
else:
data['_has_refs'] = False
Expand Down
3 changes: 3 additions & 0 deletions xobjects/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def __getitem__(cls, reftype):


class Ref(metaclass=MetaRef):

_has_refs = True

def __init__(self, reftype):
self._reftype = reftype
self.__name__ = "Ref" + self._reftype.__name__
Expand Down
5 changes: 1 addition & 4 deletions xobjects/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
"""
import logging
from typing import Callable, Optional
from .ref import Ref


from .typeutils import (
get_a_buffer,
Expand Down Expand Up @@ -251,8 +249,7 @@ def _inspect_args(cls, *args, **kwargs):
_has_refs = False
for ff in data['_fields']:
ftype = ff.ftype
if ((hasattr(ftype, '_has_refs') and ftype._has_refs)
or isinstance(ftype, Ref)):
if hasattr(ftype, '_has_refs') and ftype._has_refs:
_has_refs = True
break
data['_has_refs'] = _has_refs
Expand Down

0 comments on commit 8f6d524

Please sign in to comment.