Hello everyone I have a usecase where I'm comparing a UUID instance with string quite often. A case where I have to convert the UUID instance to a string using str(uuid_obj), leading to redundant code:
if str(uuid_obj) == uuid: # do stuff... In my experience I can't find a case where you wouldn't want the implicit conversion to string before comparing a UUID with string. So I would like to propose improving the __eq__ method of UUID to: def __eq__(self, other): if isinstance(other, UUID): return self.int == other.int elif isinstance(other, str): return str(self) == other return NotImplemented Based on my testing and experience I don't think this is a breaking change and would be a meaningful change to the way UUID works. Of course please don't hesitate to change my view or point out any flaws in my reasoning. If other people support this change I'd start the work of creating an issue and PR to get this change implemented. -- Michael Anckaert +32 474 066 467 https://www.sinax.be _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/VXLJMWZRZLSFZRNHUITSLAV2O363WG5Q/ Code of Conduct: http://python.org/psf/codeofconduct/