Skip to content

Commit

Permalink
Merge branch 'develop' into fix/5245/finalize-rename-db-migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Dec 6, 2021
2 parents 838ff90 + e3651e0 commit 3c50f26
Show file tree
Hide file tree
Showing 28 changed files with 490 additions and 348 deletions.
9 changes: 2 additions & 7 deletions aiida/orm/nodes/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@ def to_aiida_type(value):
class BaseType(Data):
"""`Data` sub class to be used as a base for data containers that represent base python data types."""

def __init__(self, *args, **kwargs):
def __init__(self, value=None, **kwargs):
try:
getattr(self, '_type')
except AttributeError:
raise RuntimeError('Derived class must define the `_type` class member')

super().__init__(**kwargs)

try:
value = args[0]
except IndexError:
value = self._type() # pylint: disable=no-member

self.value = value
self.value = value or self._type() # pylint: disable=no-member

@property
def value(self):
Expand Down
12 changes: 6 additions & 6 deletions aiida/orm/nodes/data/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ class Dict(Data):
Finally, all dictionary mutations will be forbidden once the node is stored.
"""

def __init__(self, **kwargs):
"""Store a dictionary as a `Node` instance.
def __init__(self, value=None, **kwargs):
"""Initialise a ``Dict`` node instance.
Usual rules for attribute names apply, in particular, keys cannot start with an underscore, or a `ValueError`
Usual rules for attribute names apply, in particular, keys cannot start with an underscore, or a ``ValueError``
will be raised.
Initial attributes can be changed, deleted or added as long as the node is not stored.
:param dict: the dictionary to set
:param value: dictionary to initialise the ``Dict`` node from
"""
dictionary = kwargs.pop('dict', None)
dictionary = value or kwargs.pop('dict', None)
super().__init__(**kwargs)
if dictionary:
self.set_dict(dictionary)
Expand Down Expand Up @@ -135,4 +135,4 @@ def dict(self):

@to_aiida_type.register(dict)
def _(value):
return Dict(dict=value)
return Dict(value)
16 changes: 12 additions & 4 deletions aiida/orm/nodes/data/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ class List(Data, MutableSequence):

_LIST_KEY = 'list'

def __init__(self, **kwargs):
data = kwargs.pop('list', [])
def __init__(self, value=None, **kwargs):
"""Initialise a ``List`` node instance.
:param value: list to initialise the ``List`` node from
"""
data = value or kwargs.pop('list', [])
super().__init__(**kwargs)
self.set_list(data)

Expand Down Expand Up @@ -75,7 +79,11 @@ def insert(self, i, value): # pylint: disable=arguments-renamed
self.set_list(data)

def remove(self, value):
del self[value]
data = self.get_list()
item = data.remove(value)
if not self._using_list_reference():
self.set_list(data)
return item

def pop(self, **kwargs): # pylint: disable=arguments-differ
"""Remove and return item at index (default last)."""
Expand Down Expand Up @@ -123,7 +131,7 @@ def set_list(self, data):
"""
if not isinstance(data, list):
raise TypeError('Must supply list type')
self.set_attribute(self._LIST_KEY, data)
self.set_attribute(self._LIST_KEY, data.copy())

def _using_list_reference(self):
"""
Expand Down
Loading

0 comments on commit 3c50f26

Please sign in to comment.