Enhance Color.parse method to accept tuple input for RGB values
This commit is contained in:
parent
9df06868a4
commit
e7773373f4
@ -50,7 +50,7 @@ class Color:
|
||||
return ((self.value >> 16) & 0xFF, (self.value >> 8) & 0xFF, self.value & 0xFF)
|
||||
|
||||
@classmethod
|
||||
def parse(cls, value: "Color | int | str | None") -> "Color | None":
|
||||
def parse(cls, value: "Color | int | str | tuple[int, int, int] | None") -> "Color | None":
|
||||
"""Convert ``value`` to a :class:`Color` instance.
|
||||
|
||||
Parameters
|
||||
@ -73,4 +73,6 @@ class Color:
|
||||
return cls(value)
|
||||
if isinstance(value, str):
|
||||
return cls.from_hex(value)
|
||||
raise TypeError("Color value must be Color, int, str, or None")
|
||||
if isinstance(value, tuple) and len(value) == 3:
|
||||
return cls.from_rgb(*value)
|
||||
raise TypeError("Color value must be Color, int, str, tuple, or None")
|
||||
|
Loading…
x
Reference in New Issue
Block a user