Kaydet (Commit) 632a77e6 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #22364: Improved some re error messages using regex for hints.

üst 7c316a18
...@@ -286,7 +286,7 @@ def _compile(pattern, flags): ...@@ -286,7 +286,7 @@ def _compile(pattern, flags):
if isinstance(pattern, _pattern_type): if isinstance(pattern, _pattern_type):
if flags: if flags:
raise ValueError( raise ValueError(
"Cannot process flags argument with a compiled pattern") "cannot process flags argument with a compiled pattern")
return pattern return pattern
if not sre_compile.isstring(pattern): if not sre_compile.isstring(pattern):
raise TypeError("first argument must be string or compiled pattern") raise TypeError("first argument must be string or compiled pattern")
......
...@@ -113,7 +113,7 @@ def _compile(code, pattern, flags): ...@@ -113,7 +113,7 @@ def _compile(code, pattern, flags):
emit(ANY) emit(ANY)
elif op in REPEATING_CODES: elif op in REPEATING_CODES:
if flags & SRE_FLAG_TEMPLATE: if flags & SRE_FLAG_TEMPLATE:
raise error("internal: unsupported template operator") raise error("internal: unsupported template operator %r" % (op,))
elif _simple(av) and op is not REPEAT: elif _simple(av) and op is not REPEAT:
if op is MAX_REPEAT: if op is MAX_REPEAT:
emit(REPEAT_ONE) emit(REPEAT_ONE)
...@@ -216,7 +216,7 @@ def _compile(code, pattern, flags): ...@@ -216,7 +216,7 @@ def _compile(code, pattern, flags):
else: else:
code[skipyes] = _len(code) - skipyes + 1 code[skipyes] = _len(code) - skipyes + 1
else: else:
raise ValueError("unsupported operand type", op) raise error("internal: unsupported operand type %r" % (op,))
def _compile_charset(charset, flags, code, fixup=None, fixes=None): def _compile_charset(charset, flags, code, fixup=None, fixes=None):
# compile charset subprogram # compile charset subprogram
...@@ -242,7 +242,7 @@ def _compile_charset(charset, flags, code, fixup=None, fixes=None): ...@@ -242,7 +242,7 @@ def _compile_charset(charset, flags, code, fixup=None, fixes=None):
else: else:
emit(av) emit(av)
else: else:
raise error("internal: unsupported set operator") raise error("internal: unsupported set operator %r" % (op,))
emit(FAILURE) emit(FAILURE)
def _optimize_charset(charset, fixup, fixes): def _optimize_charset(charset, fixup, fixes):
......
This diff is collapsed.
This diff is collapsed.
...@@ -30,6 +30,8 @@ Core and Builtins ...@@ -30,6 +30,8 @@ Core and Builtins
Library Library
------- -------
- Issue #22364: Improved some re error messages using regex for hints.
- Issue #23742: ntpath.expandvars() no longer loses unbalanced single quotes. - Issue #23742: ntpath.expandvars() no longer loses unbalanced single quotes.
- Issue #21717: The zipfile.ZipFile.open function now supports 'x' (exclusive - Issue #21717: The zipfile.ZipFile.open function now supports 'x' (exclusive
......
...@@ -315,7 +315,7 @@ getstring(PyObject* string, Py_ssize_t* p_length, ...@@ -315,7 +315,7 @@ getstring(PyObject* string, Py_ssize_t* p_length,
/* get pointer to byte string buffer */ /* get pointer to byte string buffer */
if (PyObject_GetBuffer(string, view, PyBUF_SIMPLE) != 0) { if (PyObject_GetBuffer(string, view, PyBUF_SIMPLE) != 0) {
PyErr_SetString(PyExc_TypeError, "expected string or buffer"); PyErr_SetString(PyExc_TypeError, "expected string or bytes-like object");
return NULL; return NULL;
} }
...@@ -359,12 +359,12 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string, ...@@ -359,12 +359,12 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
if (isbytes && pattern->isbytes == 0) { if (isbytes && pattern->isbytes == 0) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"can't use a string pattern on a bytes-like object"); "cannot use a string pattern on a bytes-like object");
goto err; goto err;
} }
if (!isbytes && pattern->isbytes > 0) { if (!isbytes && pattern->isbytes > 0) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"can't use a bytes pattern on a string-like object"); "cannot use a bytes pattern on a string-like object");
goto err; goto err;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment