summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-05-18 12:34:40 +0300
committerGitHub <noreply@github.com>2017-05-18 12:34:40 +0300
commit955b6760cfa73c54bae9b6f2b335eb0cd806c7b0 (patch)
tree25e1a106b63bf59f5f88eef54c1da48138ceba11 /Modules
parent09b52471f39ba280d836b945d47719c697af0b45 (diff)
downloadcpython-git-955b6760cfa73c54bae9b6f2b335eb0cd806c7b0.tar.gz
[2.7] bpo-30363: Backport warnings in the re module. (#1577)
Running Python with the -3 option now warns about regular expression syntax that is invalid or has different semantic in Python 3 or will change the behavior in future Python versions.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sre.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 8e16c1d140..6fd3affb09 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -2267,6 +2267,20 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
if (!string)
return NULL;
+ if (Py_Py3kWarningFlag &&
+ (self->code[0] != SRE_OP_INFO || self->code[3] == 0))
+ {
+ if (self->code[0] == SRE_OP_INFO && self->code[4] == 0) {
+ if (PyErr_WarnPy3k("split() requires a non-empty pattern match.",
+ 1) < 0)
+ return NULL;
+ }
+ else if (PyErr_WarnEx(PyExc_FutureWarning,
+ "split() requires a non-empty pattern match.",
+ 1) < 0)
+ return NULL;
+ }
+
string = state_init(&state, self, string, 0, PY_SSIZE_T_MAX);
if (!string)
return NULL;