Allow Gdk.RGBA to be compared against None
Thanks for developing PyGObject, it's really nice to be able to develop Gtk projects in Python!
I'd like to propose to that
None to be compared.
I'm updating code in a project, where I'm checking for the text's colour, from a
Gtk.TextTag which may return
None if that property is not set.
There a two ways to go around this: either check if the property is set, then query it, or check if the returned value is not
blue = Gdk.RGBA(red=0., green=0., blue=1., alpha=1.) # Case 1, check that the colour was set is_color_set = tag.get_property('foreground-set') if is_color_set and tag.get_property('foreground-rgba') == blue: ... # Case 2: check against None color = tag.get_property('foreground-rgba') if color is not None and color == blue: ...
I propose to change
Gdk.RGBA.__eq__ to something like:
def __eq__(self, other: Union['RGBA', None]) -> bool: if other is None: return False return self.equal(other)
Then we'd be able to do:
if tag.get_property('foreground-rgba') == blue: ...
self.equal is a better place to do it, as I guess it's boarder to other types as well, but I could not quickly find it.
If that's something of interest, I would not mind doing an MR myself, with a bit of guidance :)