Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Apr 10, 2024
1 parent 8f991a7 commit c14d37a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
11 changes: 5 additions & 6 deletions src/hdmf/build/classgenerator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from copy import deepcopy
from datetime import datetime, date
from collections.abc import Callable
import types as tp

import numpy as np

Expand Down Expand Up @@ -88,11 +87,8 @@ def generate_class(self, **kwargs):
+ str(e)
+ " Please define that type before defining '%s'." % name)
cls = ExtenderMeta(data_type, tuple(bases), classdict)
cls.post_init_method = post_init_method

if post_init_method is not None:
cls.post_init_method = tp.MethodType(post_init_method, cls) # set as bounded method
else:
cls.post_init_method = post_init_method # set to None
return cls


Expand Down Expand Up @@ -358,7 +354,6 @@ def __init__(self, **kwargs):
if self.post_init_method is not None:
self.post_init_method(**original_kwargs)


classdict['__init__'] = __init__


Expand Down Expand Up @@ -433,6 +428,7 @@ def set_init(cls, classdict, bases, docval_args, not_inherited_fields, name):
def __init__(self, **kwargs):
# store the values passed to init for each MCI attribute so that they can be added
# after calling __init__
original_kwargs = dict(kwargs)
new_kwargs = list()
for field_clsconf in classdict['__clsconf__']:
attr_name = field_clsconf['attr']
Expand Down Expand Up @@ -460,5 +456,8 @@ def __init__(self, **kwargs):
add_method = getattr(self, new_kwarg['add_method_name'])
add_method(new_kwarg['value'])

if self.post_init_method is not None:
self.post_init_method(**original_kwargs)

Check warning on line 460 in src/hdmf/build/classgenerator.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/build/classgenerator.py#L460

Added line #L460 was not covered by tests

# override __init__
classdict['__init__'] = __init__
18 changes: 1 addition & 17 deletions tests/unit/build_tests/test_classgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,6 @@ def test_no_generators(self):

class TestPostInitGetClass(TestCase):
def setUp(self):
# self.bar_spec = GroupSpec(
# doc='A test group specification with a data type',
# data_type_def='Bar',
# datasets=[
# DatasetSpec(
# doc='a dataset',
# dtype='int',
# name='data',
# attributes=[AttributeSpec(name='attr1', doc='an integer attribute', dtype='int')]
# )
# ])
# specs = [self.bar_spec]
# containers = {'Bar': Bar}
# from hdmf.common import get_type_map
# self.type_map = get_type_map()
# self.spec_catalog = self.type_map.namespace_catalog.get_namespace(CORE_NAMESPACE).catalog
spec = GroupSpec(
doc='A test group specification with a data type',
data_type_def='Baz',
Expand Down Expand Up @@ -132,7 +116,7 @@ def post_init_method(self, **kwargs):
cls = self.type_map.get_dt_container_cls('Baz', CORE_NAMESPACE, post_init_method)

with self.assertRaises(ValueError):
instance = cls(name='instance', attr1=9)
cls(name='instance', attr1=9)

class TestDynamicContainer(TestCase):

Expand Down

0 comments on commit c14d37a

Please sign in to comment.