Skip to content

Convert instruction classes to dataclasses #62

@TravisBumgarner

Description

@TravisBumgarner

Description

After consolidating instructions, convert them to dataclasses for cleaner definitions and automatic __init__, __repr__, etc.

Current Pattern

class InstructionPoint(_BaseInstruction):
    def __init__(self, feed_rate: float, x: float, y: float):
        self.x = x
        self.y = y
        self.feed_rate = feed_rate
        if x is None or y is None:
            raise ValueError("Point requires an X or Y")

    def __str__(self) -> str:
        return f"Point: ({self.x}, {self.y})"

    def to_g_code(self) -> str:
        return f"G1 X{self.x:.3f} Y{self.y:.3f} F{self.feed_rate}"

Proposed Pattern

@dataclass
class PointInstruction(Instruction):
    x: float
    y: float
    feed_rate: float

    def __post_init__(self) -> None:
        if self.x is None or self.y is None:
            raise ValueError("Point requires an X and Y")

    def to_g_code(self) -> str:
        return f"G1 X{self.x:.3f} Y{self.y:.3f} F{self.feed_rate}"

Acceptance Criteria

  • All instruction classes converted to dataclasses
  • Remove redundant __str__ methods where not needed
  • Validation moved to __post_init__ where applicable
  • All existing tests pass
  • mypy passes

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions