You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In src/robot/types/rgb_color_type.py ; MODIFICATION #1: Change the original method body to fix the crash from the non-existent _validate() method.
def set_color_from_hex_code(self, hex_code: str) -> None:
# Expecting format like "#RRGGBB"
try:
r = int(hex_code[1:3], 16)
g = int(hex_code[3:5], 16)
b = int(hex_code[5:7], 16)
except (ValueError, TypeError, IndexError):
# Handle bad hex codes (e.g., "#F00", "ABC", or too short)
raise RGBColorException(f"Invalid hex code format: {hex_code}")
# Use the main set_color method, which already validates 0-255
self.set_color(r, g, b)
MODIFICATION #2: Change the str method of RGBColorType to output the hex code, since that's what the system seems to use for input.
This makes the class "symmetrical": it reads hex codes, and it prints itself as a hex code.
# NEW, BETTER version
def __str__(self) -> str:
# :02x formats an integer as a 2-character hex string (e.g., 0 -> "00")
return f"#{self.R:02x}{self.G:02x}{self.B:02x}".upper()
Activity
Dinithi-Gunathilake commentedon Nov 11, 2025
In src/robot/types/rgb_color_type.py ;
MODIFICATION #1: Change the original method body to fix the crash from the non-existent _validate() method.
MODIFICATION #2: Change the str method of RGBColorType to output the hex code, since that's what the system seems to use for input.
This makes the class "symmetrical": it reads hex codes, and it prints itself as a hex code.