https://github.com/python/cpython/commit/ff3e145b2770ffe86c905b1092747ce3d8381319
commit: ff3e145b2770ffe86c905b1092747ce3d8381319
branch: main
author: Bénédikt Tran <[email protected]>
committer: picnixz <[email protected]>
date: 2025-01-14T12:26:26+01:00
summary:

gh-118761: Improve import time of the `pickle` module. (#128732)

Importing `pickle` is now roughly 25% faster.

Importing the `re` module is no longer needed and
thus `re` is no more implicitly exposed as `pickle.re`.

---------

Co-authored-by: Adam Turner <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst
M Lib/pickle.py

diff --git a/Lib/pickle.py b/Lib/pickle.py
index 1920973e3f83e9..8afb4aa4285f37 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -31,7 +31,6 @@
 import sys
 from sys import maxsize
 from struct import pack, unpack
-import re
 import io
 import codecs
 import _compat_pickle
@@ -188,7 +187,7 @@ def __init__(self, value):
 NEXT_BUFFER      = b'\x97'  # push next out-of-band buffer
 READONLY_BUFFER  = b'\x98'  # make top of stack readonly
 
-__all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]+$", x)])
+__all__.extend(x for x in dir() if x.isupper() and not x.startswith('_'))
 
 
 class _Framer:
diff --git 
a/Misc/NEWS.d/next/Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst 
b/Misc/NEWS.d/next/Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst
new file mode 100644
index 00000000000000..a0a0f891ca55d9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst
@@ -0,0 +1,3 @@
+Improve import time of :mod:`pickle` by 25% by removing an unnecessary
+regular expression. As such, :mod:`re` is no more implicitly available
+as ``pickle.re``. Patch by Bénédikt Tran.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to