From 7db778eca0cb47e48de065cd495ad78d36028006 Mon Sep 17 00:00:00 2001 From: Yosef Ashenafi Date: Wed, 22 Oct 2025 17:54:24 +0300 Subject: [PATCH 1/3] feat: add display method to HtkIntFlag for human-readable flag names ## Changes - Introduced `display` class method in `HtkIntFlag` to convert combined flag values into a list of human-readable names. - Updated docstring for `HtkIntFlag` to reflect the new functionality. This enhancement improves usability by allowing easier interpretation of combined flag values. --- utils/enums.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/utils/enums.py b/utils/enums.py index 0aa9447e..1f8f6315 100644 --- a/utils/enums.py +++ b/utils/enums.py @@ -99,7 +99,7 @@ def build_enum_data(enum_class): from enum import IntFlag class HtkIntFlag(IntFlag): - """ HTK IntFlag + """HTK IntFlag Wrapper around Python's built-in `enum.IntFlag` to provide extra functionalities. @@ -107,6 +107,30 @@ class HtkIntFlag(IntFlag): Requires: Python 3.6 or greater Reference: https://docs.python.org/3.6/library/enum.html#enum.IntFlag """ + + @classmethod + def display(cls, int_value): + """Get human-readable display names for combined flag values. + + Decomposes combined flag values using list_flags(), then uses + get_enum_symbolic_name() to format each flag. + + Args: + int_value: Combined flag value (e.g., 3 = BICEPS_BRACHII | BRACHIALIS) + + Returns: + List of human-readable flag names + + Example: + Muscle.display(3) # ['Biceps Brachii', 'Brachialis'] + Muscle.display(1) # ['Biceps Brachii'] + """ + result = [ + get_enum_symbolic_name(flag) + for flag in cls.list_flags(int_value) + ] + return result + @classmethod def list_flags(cls, int_value): """List Flags From ef1b37ee339c91f11299cc6d6b46e3c3e4242c36 Mon Sep 17 00:00:00 2001 From: Yosef Ashenafi Date: Wed, 22 Oct 2025 20:24:59 +0300 Subject: [PATCH 2/3] refactor: update display method signature to specify return type ## Changes - Modified the `display` method in `HtkIntFlag` to include a return type annotation of `list[str]`. - Enhanced the docstring with an example of how to use the `display` method with a sample class. This change improves code clarity and type safety. --- utils/enums.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/enums.py b/utils/enums.py index 1f8f6315..7a458667 100644 --- a/utils/enums.py +++ b/utils/enums.py @@ -109,7 +109,7 @@ class HtkIntFlag(IntFlag): """ @classmethod - def display(cls, int_value): + def display(cls, int_value) -> list[str]: """Get human-readable display names for combined flag values. Decomposes combined flag values using list_flags(), then uses @@ -122,6 +122,13 @@ def display(cls, int_value): List of human-readable flag names Example: + class Muscle(HtkIntFlag): + UNSPECIFIED = 0 + BICEPS_BRACHII = 1 + BRACHIALIS = 2 + BRACHIORADIALIS = 4 + TRICEPS_BRACHII = 8 + Muscle.display(3) # ['Biceps Brachii', 'Brachialis'] Muscle.display(1) # ['Biceps Brachii'] """ From 87d76b902176e4532c122efca2f475d1ba88e294 Mon Sep 17 00:00:00 2001 From: Yosef Ashenafi Date: Wed, 22 Oct 2025 21:31:01 +0300 Subject: [PATCH 3/3] refactor: add return type annotation to list_flags method ## Changes - Updated the `list_flags` method in `HtkIntFlag` to specify a return type of `list[HtkIntFlag]`. - Enhanced the method's docstring for improved clarity. This change enhances code readability and type safety. --- utils/enums.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/enums.py b/utils/enums.py index 7a458667..fa89e7b2 100644 --- a/utils/enums.py +++ b/utils/enums.py @@ -139,7 +139,7 @@ class Muscle(HtkIntFlag): return result @classmethod - def list_flags(cls, int_value): + def list_flags(cls, int_value) -> list[HtkIntFlag]: """List Flags Returns the list of flags that value contains, running bitwise