From e5070789ccb8e42e720d10b15ccd21ead865c375 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 18 Dec 2025 12:16:02 +0000 Subject: [PATCH] PYTHON-5679 Optimize `ObjectId.__str__()` (#2657) Co-authored-by: Steven Silvester --- bson/objectid.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bson/objectid.py b/bson/objectid.py index 970c4e52e..d3c64ef7c 100644 --- a/bson/objectid.py +++ b/bson/objectid.py @@ -15,7 +15,6 @@ """Tools for working with MongoDB ObjectIds.""" from __future__ import annotations -import binascii import datetime import os import struct @@ -234,7 +233,7 @@ class ObjectId: self.__id = oid def __str__(self) -> str: - return binascii.hexlify(self.__id).decode() + return self.__id.hex() def __repr__(self) -> str: return f"ObjectId('{self!s}')"