PYTHON-5679 Optimize ObjectId.__str__() (#2657)

Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
This commit is contained in:
Adam Johnson 2025-12-18 12:16:02 +00:00 committed by GitHub
parent 60289f0398
commit e5070789cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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}')"