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):
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError(
"Cannot process flags argument with a compiled pattern")
"cannot process flags argument with a compiled pattern")
return pattern
if not sre_compile.isstring(pattern):
raise TypeError("first argument must be string or compiled pattern")
......
......@@ -113,7 +113,7 @@ def _compile(code, pattern, flags):
emit(ANY)
elif op in REPEATING_CODES:
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:
if op is MAX_REPEAT:
emit(REPEAT_ONE)
......@@ -216,7 +216,7 @@ def _compile(code, pattern, flags):
else:
code[skipyes] = _len(code) - skipyes + 1
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):
# compile charset subprogram
......@@ -242,7 +242,7 @@ def _compile_charset(charset, flags, code, fixup=None, fixes=None):
else:
emit(av)
else:
raise error("internal: unsupported set operator")
raise error("internal: unsupported set operator %r" % (op,))
emit(FAILURE)
def _optimize_charset(charset, fixup, fixes):
......
This diff is collapsed.
This diff is collapsed.
......@@ -30,6 +30,8 @@ Core and Builtins
Library
-------
- Issue #22364: Improved some re error messages using regex for hints.
- Issue #23742: ntpath.expandvars() no longer loses unbalanced single quotes.
- Issue #21717: The zipfile.ZipFile.open function now supports 'x' (exclusive
......
......@@ -315,7 +315,7 @@ getstring(PyObject* string, Py_ssize_t* p_length,
/* get pointer to byte string buffer */
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;
}
......@@ -359,12 +359,12 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
if (isbytes && pattern->isbytes == 0) {
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;
}
if (!isbytes && pattern->isbytes > 0) {
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;
}
......
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