Skip to content

Commit

Permalink
Add QbField.annotation property and make Group.field.extras subsc…
Browse files Browse the repository at this point in the history
…riptable (aiidateam#6343)

- Missing `Group.fields.extras` subscriptability added
- `QbField.dtype` now returns root primitive type (more useful in practice)
- `QbField.annotation` provides the full type annotation
  • Loading branch information
edan-bainglass authored Apr 10, 2024
1 parent 43a7d77 commit 0dca43c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/aiida/orm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ def doc(self) -> str:

@property
def dtype(self) -> t.Optional[t.Any]:
return self._dtype

def get_root_type(self) -> t.Optional[t.Any]:
"""Return the primitive root type."""
return extract_root_type(self._dtype)

@property
def annotation(self) -> t.Optional[t.Any]:
"""Return the full type annotation."""
return self._dtype

@property
def is_attribute(self) -> bool:
return self._is_attribute
Expand Down
1 change: 1 addition & 0 deletions src/aiida/orm/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class Group(entities.Entity['BackendGroup', GroupCollection]):
'extras',
dtype=Dict[str, Any],
is_attribute=False,
is_subscriptable=True,
doc='The group extras',
),
add_field(
Expand Down
2 changes: 1 addition & 1 deletion tests/orm/test_fields/fields_Group.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: QbStrField('description', dtype=str, is_attribute=False)
extras: QbDictField('extras', dtype=Dict[str, Any], is_attribute=False)
extras: QbDictField('extras', dtype=Dict[str, Any], is_attribute=False, is_subscriptable=True)
label: QbStrField('label', dtype=str, is_attribute=False)
pk: QbNumericField('pk', dtype=int, is_attribute=False)
time: QbStrField('time', dtype=str, is_attribute=False)
Expand Down

0 comments on commit 0dca43c

Please sign in to comment.