Skip to content

Commit ff3e145

Browse files
picnixzAA-Turner
andauthored
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]>
1 parent 1153e66 commit ff3e145

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Diff for: Lib/pickle.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import sys
3232
from sys import maxsize
3333
from struct import pack, unpack
34-
import re
3534
import io
3635
import codecs
3736
import _compat_pickle
@@ -188,7 +187,7 @@ def __init__(self, value):
188187
NEXT_BUFFER = b'\x97' # push next out-of-band buffer
189188
READONLY_BUFFER = b'\x98' # make top of stack readonly
190189

191-
__all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]+$", x)])
190+
__all__.extend(x for x in dir() if x.isupper() and not x.startswith('_'))
192191

193192

194193
class _Framer:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improve import time of :mod:`pickle` by 25% by removing an unnecessary
2+
regular expression. As such, :mod:`re` is no more implicitly available
3+
as ``pickle.re``. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)