There was an error while loading. Please reload this page.
re
locale
1 parent 3796884 commit cf5e438Copy full SHA for cf5e438
2 files changed
Lib/locale.py
@@ -13,7 +13,6 @@
13
import sys
14
import encodings
15
import encodings.aliases
16
-import re
17
import _collections_abc
18
from builtins import str as _builtin_str
19
import functools
@@ -177,8 +176,7 @@ def _strip_padding(s, amount):
177
176
amount -= 1
178
return s[lpos:rpos+1]
179
180
-_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
181
- r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
+_percent_re = None
182
183
def _format(percent, value, grouping=False, monetary=False, *additional):
184
if additional:
@@ -217,6 +215,13 @@ def format_string(f, val, grouping=False, monetary=False):
217
215
Grouping is applied if the third parameter is true.
218
216
Conversion uses monetary thousands separator and grouping strings if
219
forth parameter monetary is true."""
+ global _percent_re
+ if _percent_re is None:
220
+ import re
221
+
222
+ _percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?(?P<modifiers'
223
+ r'>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
224
225
percents = list(_percent_re.finditer(f))
226
new_f = _percent_re.sub('%s', f)
227
Misc/NEWS.d/next/Library/2025-02-08-21-37-05.gh-issue-118761.EtqxeB.rst
@@ -0,0 +1,2 @@
1
+Improve import time of :mod:`locale` using lazy import ``re``. Patch by
2
+Semyon Moroz.
0 commit comments