From e994e028cf18efab8c4d42b6279aac49bc87479b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:33:49 +0100 Subject: [PATCH 1/5] Improve import time of the `pickle` module. Importing `pickle` is now roughly 25% faster. Importing the `re` module is no longer needed and thus is no more implicitly exposed as `pickle.re`. --- Lib/pickle.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/pickle.py b/Lib/pickle.py index 1920973e3f83e9..41dcfac24993d6 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,8 +187,10 @@ 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 x.isidentifier() and not x.startswith('_') +]) class _Framer: From 6ce778552e04ecdaae92fb73e694eaa3278e6897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:34:36 +0100 Subject: [PATCH 2/5] blurb --- .../next/Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst 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..9bc3530aa06ea3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst @@ -0,0 +1,2 @@ +Improve import time of :mod:`pickle` by 25% by removing an un-necessary +import to :mod:`re`. Patch by Bénédikt Tran. From 2b7bfd993c103f79891dbe319d14f0d4875dce8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 12 Jan 2025 19:11:19 +0100 Subject: [PATCH 3/5] Simplify `__all__` extension Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Lib/pickle.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Lib/pickle.py b/Lib/pickle.py index 41dcfac24993d6..9d195888f8a977 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -187,10 +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 x.isupper() and x.isidentifier() and not x.startswith('_') -]) +__all__.extend(x for x in dir() if x.isupper() and not x.startswith('_')) class _Framer: From 4063875b8807a73804073d26158247660e38c5cf Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 12 Jan 2025 18:21:33 +0000 Subject: [PATCH 4/5] PEP 8 (whitespace) --- Lib/pickle.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/pickle.py b/Lib/pickle.py index 9d195888f8a977..8afb4aa4285f37 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -189,6 +189,7 @@ def __init__(self, value): __all__.extend(x for x in dir() if x.isupper() and not x.startswith('_')) + class _Framer: _FRAME_SIZE_MIN = 4 From 17242dd6c28d2543eb4236f8ba4640a004c8a087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:36:54 +0100 Subject: [PATCH 5/5] update NEWS --- .../Library/2025-01-10-13-34-33.gh-issue-118761.qRB8nS.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 index 9bc3530aa06ea3..a0a0f891ca55d9 100644 --- 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 @@ -1,2 +1,3 @@ -Improve import time of :mod:`pickle` by 25% by removing an un-necessary -import to :mod:`re`. Patch by Bénédikt Tran. +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.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: