]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-118761: Improve the import time of ``gettext`` (#128898)
authorEli Schwartz <eschwartz@gentoo.org>
Mon, 20 Jan 2025 00:01:20 +0000 (19:01 -0500)
committerGitHub <noreply@github.com>
Mon, 20 Jan 2025 00:01:20 +0000 (00:01 +0000)
commitc9c9fcb8fcc3ef43e1d8bd71ae0ed3d4231a6013
treece7485a3e9f05c2336a350b2b3590a47332e7dd1
parentbbeb219354764aef85e660be6570f0f329e7227e
gh-118761: Improve the import time of ``gettext`` (#128898)

``gettext`` is often imported in programs that may not end up translating
anything. In fact, the ``struct`` module already has a delayed import when
parsing ``GNUTranslations`` to speed up the no ``.mo`` files case. The re module
is also used in the same situation, but behind a function chain only
called by ``GNUTranslations``.

Cache the compiled regex globally the first time it is used. The
finditer function is converted to a method call on the compiled
object which is slightly more efficient, and necessary for the
delayed re import.
Lib/gettext.py
Misc/NEWS.d/next/Library/2025-01-15-19-16-50.gh-issue-118761.cbW2ZL.rst [new file with mode: 0644]