Skip to content

Commit

Permalink
fix get_class with supplied name (#51)
Browse files Browse the repository at this point in the history
* carry spec.name through to get_cls_dict
* if name is in spec fields, remove from docval and add directly to args in __init__
* call base class to fix inheritance problem
  • Loading branch information
bendichter committed May 7, 2019
1 parent e0d863d commit 2cb86fa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/hdmf/build/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ def __ischild(self, dtype):
ret = True
return ret

def __get_cls_dict(self, base, addl_fields):
def __get_cls_dict(self, base, addl_fields, name=None):
# TODO: fix this to be more maintainable and smarter
if base is None:
raise ValueError('cannot generate class without base class')
Expand Down Expand Up @@ -1400,11 +1400,15 @@ def __get_cls_dict(self, base, addl_fields):
fields.append({'name': f, 'child': True})
else:
fields.append(f)
if name is not None:
docval_args = filter(lambda x: x['name'] != 'name', docval_args)

@docval(*docval_args)
def __init__(self, **kwargs):
pargs, pkwargs = fmt_docval_args(base.__init__, kwargs)
super(type(self), self).__init__(*pargs, **pkwargs)
if name is not None:
pargs.insert(0, name)
base.__init__(self, *pargs, **pkwargs)
for f in new_args:
setattr(self, f, kwargs.get(f, None))

Expand Down Expand Up @@ -1447,7 +1451,7 @@ def get_container_cls(self, **kwargs):
for k, field_spec in attr_names.items():
if not spec.is_inherited_spec(field_spec):
fields[k] = field_spec
d = self.__get_cls_dict(parent_cls, fields)
d = self.__get_cls_dict(parent_cls, fields, spec.name)
cls = ExtenderMeta(str(name), bases, d)
self.register_container_type(namespace, data_type, cls)
return cls
Expand Down

0 comments on commit 2cb86fa

Please sign in to comment.