diff --git a/j5/components/piezo.py b/j5/components/piezo.py index 48a0a106..f77a11f3 100644 --- a/j5/components/piezo.py +++ b/j5/components/piezo.py @@ -3,7 +3,7 @@ from abc import abstractmethod from datetime import timedelta from enum import IntEnum -from typing import Type, Union +from typing import Generator, Type, Union from j5.boards import Board from j5.components import Component, Interface @@ -31,6 +31,12 @@ class Note(IntEnum): A7 = 3520 B7 = 3951 + def __reverse__(self) -> Generator['Note', None, None]: + # Type is ignored because of an open bug within mypy + # https://github.com/python/typeshed/issues/1590 + # https://github.com/python/typeshed/issues/1595 + yield from reversed(self.__members__.items()) # type: ignore + Pitch = Union[int, Note] diff --git a/tests/components/test_piezo.py b/tests/components/test_piezo.py index 6de3e343..20496fc6 100644 --- a/tests/components/test_piezo.py +++ b/tests/components/test_piezo.py @@ -82,3 +82,8 @@ def test_piezo_buzz_invalid_value(): piezo.buzz(MockPiezoBoard, 0, 0, -42) with pytest.raises(TypeError): piezo.buzz(MockPiezoBoard, 0, 0, "j5") + + +def test_note_reversed(): + """Test Note reversed dunder method.""" + assert list(reversed(list(Note))) == list(reversed(Note))