Skip to content

Instantly share code, notes, and snippets.

@weishi-imbue
Last active April 17, 2026 23:54
Show Gist options
  • Select an option

  • Save weishi-imbue/6d4e90029678605ad7ddcba6a3d7fe4c to your computer and use it in GitHub Desktop.

Select an option

Save weishi-imbue/6d4e90029678605ad7ddcba6a3d7fe4c to your computer and use it in GitHub Desktop.
def _parse_value(self, val: str, maxval: int = 255) -> int:
try:
return int(val)
except ValueError:
pass
if val.endswith('%'):
val = val[:-1]
- mult = maxval / 100
+ try:
+ return round(float(val) * maxval / 100)
+ except ValueError:
+ raise configexc.ValidationError(val, "must be a valid color value")
else:
- mult = maxval / 1.0
-
- try:
- return int(float(val) * mult)
- except ValueError:
- raise configexc.ValidationError(val, "must be a valid color value")
+ try:
+ return round(float(val))
+ except ValueError:
+ raise configexc.ValidationError(val, "must be a valid color value")
@weishi-imbue

Copy link
Copy Markdown
Author

Error in line 22.
When input val = '1.0', representing the alpha (transparency) channel, expected output is 255, not 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment