Summary
TypeStatus and TypeExecution are plain classes with string class attributes. They lack type safety, validation, iteration, and membership testing that Python's `Enum` provides.
Current Code
# dotflow/core/types/status.py
class TypeStatus:
NOT_STARTED = "Not started"
IN_PROGRESS = "In progress"
COMPLETED = "Completed"
PAUSED = "Paused"
RETRY = "Retry"
FAILED = "Failed"
# dotflow/core/types/execution.py
class TypeExecution:
SEQUENTIAL = "sequential"
BACKGROUND = "background"
PARALLEL = "parallel"
Problems
1. No validation — any string is accepted
task.status = "banana" # no error, silently accepted
task.status = "completed" # wrong case, silently accepted (should be "Completed")
task.status = "" # empty string, silently accepted
2. No membership testing
# Can't do this:
"Completed" in TypeStatus # TypeError: argument of type 'type' is not iterable
# Have to manually check:
if mode not in {"sequential", "sequential_group", "background", "parallel"}:
raise ExecutionModeNotExist()
This manual check exists in Manager.__init__ and would be unnecessary with an Enum.
3. No iteration
# Can't list all statuses:
list(TypeStatus) # TypeError
# Would need to manually maintain lists like in get_symbol():
status = {
TypeStatus.NOT_STARTED: "⚪",
TypeStatus.IN_PROGRESS: "🔵",
# ... must keep in sync manually
}
4. Comparison is by string value, not identity
TypeStatus.COMPLETED == "Completed" # True — but also:
"Completed" == TypeStatus.COMPLETED # True
# This means typos go unnoticed:
if task.status == "completed": # always False, no error raised
print("done")
Proposed Fix
TypeStatus
# dotflow/core/types/status.py
from enum import StrEnum
class TypeStatus(StrEnum):
NOT_STARTED = "Not started"
IN_PROGRESS = "In progress"
COMPLETED = "Completed"
PAUSED = "Paused"
RETRY = "Retry"
FAILED = "Failed"
@property
def symbol(self) -> str:
symbols = {
TypeStatus.NOT_STARTED: "⚪",
TypeStatus.IN_PROGRESS: "🔵",
TypeStatus.COMPLETED: "✅",
TypeStatus.PAUSED: "◼️",
TypeStatus.RETRY: "❗",
TypeStatus.FAILED: "❌",
}
return symbols[self]
TypeExecution
# dotflow/core/types/execution.py
from enum import StrEnum
class TypeExecution(StrEnum):
SEQUENTIAL = "sequential"
SEQUENTIAL_GROUP = "sequential_group"
BACKGROUND = "background"
PARALLEL = "parallel"
Why StrEnum
StrEnum (Python 3.11+) inherits from str, so TypeStatus.COMPLETED == "Completed" still works. This makes the migration backward-compatible — existing comparisons against string literals won't break.
For Python 3.10 support, use the backport from enum:
# Python 3.10 compatible:
class TypeStatus(str, Enum):
...
Benefits after migration
# Validation:
TypeStatus("banana") # ValueError: 'banana' is not a valid TypeStatus
# Membership:
"Completed" in TypeStatus # True (with StrEnum)
# Iteration:
for s in TypeStatus:
print(s.name, s.value, s.symbol)
# Manager.__init__ simplification:
# Before:
VALID_MODES = {"sequential", "sequential_group", "background", "parallel"}
if mode not in VALID_MODES:
raise ExecutionModeNotExist()
# After:
try:
mode = TypeExecution(mode)
except ValueError:
raise ExecutionModeNotExist()
Notes
StrEnum ensures backward compatibility with existing == "string" comparisons
get_symbol() classmethod can become a symbol property on each enum member
SEQUENTIAL_GROUP is missing from TypeExecution today — it's handled as a string "sequential_group" in Manager but not declared as a constant
- If the project needs to support Python < 3.11, use
class TypeStatus(str, Enum) instead of StrEnum
Checklist
Summary
TypeStatusandTypeExecutionare plain classes with string class attributes. They lack type safety, validation, iteration, and membership testing that Python's `Enum` provides.Current Code
Problems
1. No validation — any string is accepted
2. No membership testing
This manual check exists in
Manager.__init__and would be unnecessary with an Enum.3. No iteration
4. Comparison is by string value, not identity
Proposed Fix
TypeStatus
TypeExecution
Why
StrEnumStrEnum(Python 3.11+) inherits fromstr, soTypeStatus.COMPLETED == "Completed"still works. This makes the migration backward-compatible — existing comparisons against string literals won't break.For Python 3.10 support, use the backport from
enum:Benefits after migration
Notes
StrEnumensures backward compatibility with existing== "string"comparisonsget_symbol()classmethod can become asymbolproperty on each enum memberSEQUENTIAL_GROUPis missing fromTypeExecutiontoday — it's handled as a string"sequential_group"inManagerbut not declared as a constantclass TypeStatus(str, Enum)instead ofStrEnumChecklist
TypeStatustoStrEnum(orstr, Enumfor 3.10)TypeExecutiontoStrEnumSEQUENTIAL_GROUPtoTypeExecutionget_symbolclassmethod with asymbolpropertyManager.__init__mode validation using the enumTask.statussetter to accept onlyTypeStatusvalues