Skip to content

Commit b09184b

Browse files
bpo-47211: Remove function re.template() and flag re.TEMPLATE (GH-32300)
They were undocumented and never working.
1 parent da92240 commit b09184b

File tree

8 files changed

+7
-18
lines changed

8 files changed

+7
-18
lines changed

Lib/re/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
# public symbols
130130
__all__ = [
131131
"match", "fullmatch", "search", "sub", "subn", "split",
132-
"findall", "finditer", "compile", "purge", "template", "escape",
132+
"findall", "finditer", "compile", "purge", "escape",
133133
"error", "Pattern", "Match", "A", "I", "L", "M", "S", "X", "U",
134134
"ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE",
135135
"UNICODE", "NOFLAG", "RegexFlag",
@@ -148,8 +148,6 @@ class RegexFlag:
148148
MULTILINE = M = _compiler.SRE_FLAG_MULTILINE # make anchors look for newline
149149
DOTALL = S = _compiler.SRE_FLAG_DOTALL # make dot match newline
150150
VERBOSE = X = _compiler.SRE_FLAG_VERBOSE # ignore whitespace and comments
151-
# sre extensions (experimental, don't rely on these)
152-
TEMPLATE = T = _compiler.SRE_FLAG_TEMPLATE # disable backtracking
153151
DEBUG = _compiler.SRE_FLAG_DEBUG # dump pattern after compilation
154152
__str__ = object.__str__
155153
_numeric_repr_ = hex
@@ -231,10 +229,6 @@ def purge():
231229
_cache.clear()
232230
_compile_repl.cache_clear()
233231

234-
def template(pattern, flags=0):
235-
"Compile a template pattern, returning a Pattern object"
236-
return _compile(pattern, flags|T)
237-
238232
# SPECIAL_CHARS
239233
# closing ')', '}' and ']'
240234
# '-' (a range in character set)

Lib/re/_compiler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ def _compile(data, pattern, flags):
147147
else:
148148
emit(ANY)
149149
elif op in REPEATING_CODES:
150-
if flags & SRE_FLAG_TEMPLATE:
151-
raise error("internal: unsupported template operator %r" % (op,))
152150
if _simple(av[2]):
153151
emit(REPEATING_CODES[op][2])
154152
skip = _len(code); emit(0)

Lib/re/_constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ def _makecodes(names):
202202
}
203203

204204
# flags
205-
SRE_FLAG_TEMPLATE = 1 # template mode (disable backtracking)
206205
SRE_FLAG_IGNORECASE = 2 # case insensitive
207206
SRE_FLAG_LOCALE = 4 # honour system locale
208207
SRE_FLAG_MULTILINE = 8 # treat target as multiline string
@@ -245,7 +244,6 @@ def dump(f, d, prefix):
245244
dump(f, ATCODES, "SRE")
246245
dump(f, CHCODES, "SRE")
247246

248-
f.write("#define SRE_FLAG_TEMPLATE %d\n" % SRE_FLAG_TEMPLATE)
249247
f.write("#define SRE_FLAG_IGNORECASE %d\n" % SRE_FLAG_IGNORECASE)
250248
f.write("#define SRE_FLAG_LOCALE %d\n" % SRE_FLAG_LOCALE)
251249
f.write("#define SRE_FLAG_MULTILINE %d\n" % SRE_FLAG_MULTILINE)

Lib/re/_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@
6161
"x": SRE_FLAG_VERBOSE,
6262
# extensions
6363
"a": SRE_FLAG_ASCII,
64-
"t": SRE_FLAG_TEMPLATE,
6564
"u": SRE_FLAG_UNICODE,
6665
}
6766

6867
TYPE_FLAGS = SRE_FLAG_ASCII | SRE_FLAG_LOCALE | SRE_FLAG_UNICODE
69-
GLOBAL_FLAGS = SRE_FLAG_DEBUG | SRE_FLAG_TEMPLATE
68+
GLOBAL_FLAGS = SRE_FLAG_DEBUG
7069

7170
class Verbose(Exception):
7271
pass

Lib/test/test_re.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,11 +2432,11 @@ def test_flags_repr(self):
24322432
"re.IGNORECASE|re.DOTALL|re.VERBOSE|0x100000")
24332433
self.assertEqual(
24342434
repr(~re.I),
2435-
"re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.DOTALL|re.VERBOSE|re.TEMPLATE|re.DEBUG")
2435+
"re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.DOTALL|re.VERBOSE|re.DEBUG|0x1")
24362436
self.assertEqual(repr(~(re.I|re.S|re.X)),
2437-
"re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.TEMPLATE|re.DEBUG")
2437+
"re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.DEBUG|0x1")
24382438
self.assertEqual(repr(~(re.I|re.S|re.X|(1<<20))),
2439-
"re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.TEMPLATE|re.DEBUG|0xffe00")
2439+
"re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.DEBUG|0xffe01")
24402440

24412441

24422442
class ImplementationTest(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove undocumented and never working function ``re.template()`` and flag
2+
``re.TEMPLATE``.

Modules/_sre/sre.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,6 @@ pattern_repr(PatternObject *obj)
13231323
const char *name;
13241324
int value;
13251325
} flag_names[] = {
1326-
{"re.TEMPLATE", SRE_FLAG_TEMPLATE},
13271326
{"re.IGNORECASE", SRE_FLAG_IGNORECASE},
13281327
{"re.LOCALE", SRE_FLAG_LOCALE},
13291328
{"re.MULTILINE", SRE_FLAG_MULTILINE},

Modules/_sre/sre_constants.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
#define SRE_CATEGORY_UNI_NOT_WORD 15
8787
#define SRE_CATEGORY_UNI_LINEBREAK 16
8888
#define SRE_CATEGORY_UNI_NOT_LINEBREAK 17
89-
#define SRE_FLAG_TEMPLATE 1
9089
#define SRE_FLAG_IGNORECASE 2
9190
#define SRE_FLAG_LOCALE 4
9291
#define SRE_FLAG_MULTILINE 8

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy