]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118761: Improve import time of the `pickle` module. (#128732)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Tue, 14 Jan 2025 11:26:26 +0000 (12:26 +0100)
committerGitHub <noreply@github.com>
Tue, 14 Jan 2025 11:26:26 +0000 (12:26 +0100)
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 <9087854+AA-Turner@users.noreply.github.com>
Lib/pickle.py
Misc/NEWS.d/next/Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst [new file with mode: 0644]

index 1920973e3f83e974a5eb6824a7442166f108b898..8afb4aa4285f3725646ca566bf91d382dcef4c55 100644 (file)
@@ -31,7 +31,6 @@ from functools import partial
 import sys
 from sys import maxsize
 from struct import pack, unpack
-import re
 import io
 import codecs
 import _compat_pickle
@@ -188,7 +187,7 @@ BYTEARRAY8       = b'\x96'  # push bytearray
 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 (file)
index 0000000..a0a0f89
--- /dev/null
@@ -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.