Skip to content

Add __repr__ to Context, DotFlow, and TaskError classes #193

@FernandoCelmer

Description

@FernandoCelmer

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

  1. Add the __repr__ method to each class
  2. Add a test for each (e.g. assert "task_id=0" in repr(Context(task_id=0)))
  3. Each method is 1-3 lines — no dependencies, no logic changes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions