Description
Three core classes have no __repr__, making debugging and REPL inspection difficult.
The problem
>>> ctx = Context(task_id=0, storage={"users": 150})
>>> print(ctx)
<dotflow.core.context.Context object at 0x104a2b3d0>
This tells the developer nothing useful. The same happens with DotFlow and TaskError.
The fix
Context (dotflow/core/context.py)
def __repr__(self) -> str:
return f"Context(task_id={self.task_id}, workflow_id={self.workflow_id}, storage={self.storage!r})"
Result: Context(task_id=0, workflow_id=None, storage={'users': 150})
DotFlow (dotflow/core/dotflow.py)
def __repr__(self) -> str:
return f"DotFlow(workflow_id={self.workflow_id}, tasks={len(self.task.queue)})"
Result: DotFlow(workflow_id=550e8400-..., tasks=3)
TaskError (dotflow/core/exception.py)
def __repr__(self) -> str:
return f"TaskError(exception={self.exception!r}, message={self.message!r}, attempt={self.attempt})"
Result: TaskError(exception='ValueError', message='connection refused', attempt=2)
Why this matters
- Debugging:
print(task.errors) shows useful info instead of memory addresses
- Logging: log messages include readable object state
- REPL: interactive exploration actually works
How to implement
- Add the
__repr__ method to each class
- Add a test for each (e.g.
assert "task_id=0" in repr(Context(task_id=0)))
- Each method is 1-3 lines — no dependencies, no logic changes
Description
Three core classes have no
__repr__, making debugging and REPL inspection difficult.The problem
This tells the developer nothing useful. The same happens with
DotFlowandTaskError.The fix
Context (
dotflow/core/context.py)Result:
Context(task_id=0, workflow_id=None, storage={'users': 150})DotFlow (
dotflow/core/dotflow.py)Result:
DotFlow(workflow_id=550e8400-..., tasks=3)TaskError (
dotflow/core/exception.py)Result:
TaskError(exception='ValueError', message='connection refused', attempt=2)Why this matters
print(task.errors)shows useful info instead of memory addressesHow to implement
__repr__method to each classassert "task_id=0" in repr(Context(task_id=0)))