Skip to content

Commit

Permalink
ORM: add EnumData plugin to to_aiida_type dispatch (#5314)
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber authored Jan 19, 2022
1 parent ad28e9b commit 44577af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions aiida/orm/nodes/data/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ class Color(Enum):

from aiida.common.lang import type_check

from .base import to_aiida_type
from .data import Data

__all__ = ('EnumData',)

EnumType = t.TypeVar('EnumType', bound=Enum)


@to_aiida_type.register(Enum)
def _(value):
return EnumData(member=value)


class EnumData(Data):
"""Data plugin that allows to easily wrap an :class:`enum.Enum` member.
Expand Down
2 changes: 2 additions & 0 deletions tests/orm/nodes/data/test_to_aiida_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pytest

from aiida import orm
from aiida.common.links import LinkType


#yapf: disable
Expand All @@ -23,6 +24,7 @@
(orm.Int, 5),
(orm.List, [0, 1, 2]),
(orm.Str, 'test-string'),
(orm.EnumData, LinkType.RETURN),
)
)
# yapf: enable
Expand Down

0 comments on commit 44577af

Please sign in to comment.