Skip to content

Commit 25e8ebc

Browse files
committed
Add docstrings to comparison and representation methods in Color class for clarity
1 parent 9941c81 commit 25e8ebc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

py/selenium/webdriver/support/color.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,56 @@ def hex(self) -> str:
152152
return f"#{self.red:02x}{self.green:02x}{self.blue:02x}"
153153

154154
def __eq__(self, other: object) -> bool:
155+
"""Compare this Color with another object for equality.
156+
157+
Args:
158+
other: The object to compare with.
159+
160+
Returns:
161+
True if both are Color objects with the same RGBA values, False
162+
otherwise. Returns NotImplemented if other is not a Color.
163+
"""
155164
if isinstance(other, Color):
156165
return self.rgba == other.rgba
157166
return NotImplemented
158167

159168
def __ne__(self, other: Any) -> bool:
169+
"""Compare this Color with another object for inequality.
170+
171+
Args:
172+
other: The object to compare with.
173+
174+
Returns:
175+
True if the objects are not equal, False otherwise. Returns
176+
NotImplemented if the comparison is not supported.
177+
"""
160178
result = self.__eq__(other)
161179
if result is NotImplemented:
162180
return result
163181
return not result
164182

165183
def __hash__(self) -> int:
184+
"""Return the hash code for this Color.
185+
186+
Returns:
187+
The integer hash of the Color's RGBA values.
188+
"""
166189
return hash((self.red, self.green, self.blue, self.alpha))
167190

168191
def __repr__(self) -> str:
192+
"""Return a string representation of the Color object.
193+
194+
Returns:
195+
A string representation showing all RGBA components.
196+
"""
169197
return f"Color(red={self.red}, green={self.green}, blue={self.blue}, alpha={self.alpha})"
170198

171199
def __str__(self) -> str:
200+
"""Return a string representation of the Color.
201+
202+
Returns:
203+
A user-friendly string showing the RGBA value.
204+
"""
172205
return f"Color: {self.rgba}"
173206

174207

0 commit comments

Comments
 (0)