From 98974e22e2f0c98737c1a0d940058d1fe298e178 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 27 Oct 2025 12:11:38 +0200 Subject: [PATCH] Improve `uuid.__str__()` performance a little more --- Lib/uuid.py | 2 +- .../next/Library/2025-10-27-12-16-34.gh-issue-131196.nLpXzf.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-10-27-12-16-34.gh-issue-131196.nLpXzf.rst diff --git a/Lib/uuid.py b/Lib/uuid.py index c0150a59d7cb9a..975a6438a12092 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -329,7 +329,7 @@ def __setattr__(self, name, value): raise TypeError('UUID objects are immutable') def __str__(self): - x = self.hex + x = self.int.to_bytes(16).hex() return f'{x[:8]}-{x[8:12]}-{x[12:16]}-{x[16:20]}-{x[20:]}' @property diff --git a/Misc/NEWS.d/next/Library/2025-10-27-12-16-34.gh-issue-131196.nLpXzf.rst b/Misc/NEWS.d/next/Library/2025-10-27-12-16-34.gh-issue-131196.nLpXzf.rst new file mode 100644 index 00000000000000..727237608cac31 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-27-12-16-34.gh-issue-131196.nLpXzf.rst @@ -0,0 +1 @@ +Improve performance of :meth:`uuid.UUID.__str__ `.