Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix improperly set new vs overridden attributes #448

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
- Fix convert dtype when writing numpy array from `h5py.Dataset`. @rly (#427)
- Fix inheritance when non-`AbstractContainer` is base class. @rly (#444)
- Fix use of `hdmf.testing.assertContainerEqual(...)` for `Data` objects. @rly (#445)
- Fix bug in BaseStorageSpec.resolve_spec where attributes are not correctly removed from the set of new attributes.
@rly (#448)

## HDMF 2.2.0 (August 14, 2020)

Expand Down
4 changes: 2 additions & 2 deletions src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def __gather_fields(cls, name, bases, classdict):
# check whether new fields spec already exists in base class
for field_name in fields_dict:
if field_name in base_fields:
raise ValueError("Field '%s' cannot be defined in %s. It already exists on base class %s."
% (field_name, cls.__name__, base_cls.__name__))
warn("Field '%s' should not be defined in %s. It already exists on base class %s."
% (field_name, cls.__name__, base_cls.__name__))
# prepend field specs from base class to fields list of this class
all_fields_conf[0:0] = base_cls.get_fields_conf()

Expand Down
2 changes: 1 addition & 1 deletion src/hdmf/spec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def required(self):
def resolve_spec(self, **kwargs):
inc_spec = getargs('inc_spec', kwargs)
for attribute in inc_spec.attributes:
self.__new_attributes.discard(attribute)
self.__new_attributes.discard(attribute.name)
if attribute.name in self.__attributes:
self.__overridden_attributes.add(attribute.name)
continue
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ def test_inheritance_override(self):
class NamedFields(AbstractContainer):
__fields__ = ({'name': 'field1'}, )

msg = ("Field 'field1' cannot be defined in NamedFieldsChild. It already exists on base class "
msg = ("Field 'field1' should not be defined in NamedFieldsChild. It already exists on base class "
"NamedFields.")
with self.assertRaisesWith(ValueError, msg):
with self.assertWarnsWith(UserWarning, msg):
class NamedFieldsChild(NamedFields):
__fields__ = ({'name': 'field1', 'settable': True}, )

Expand Down