[issue20283] Wrong keyword parameter name in regex pattern methods
Roundup Robot added the comment: New changeset 52743dc788e6 by Serhiy Storchaka in branch '3.3': Issue #20283: RE pattern methods now accept the string keyword parameters http://hg.python.org/cpython/rev/52743dc788e6 New changeset f4d7abcf8080 by Serhiy Storchaka in branch 'default': Issue #20283: RE pattern methods now accept the string keyword parameters http://hg.python.org/cpython/rev/f4d7abcf8080 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Roundup Robot added the comment: New changeset 52256a5861fa by Serhiy Storchaka in branch '2.7': Issue #20283: RE pattern methods now accept the string keyword parameters http://hg.python.org/cpython/rev/52256a5861fa -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Serhiy Storchaka storch...@gmail.com: -- assignee: - serhiy.storchaka resolution: - fixed stage: patch review - committed/rejected ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: Here is a test. -- Added file: http://bugs.python.org/file34290/test_re_keyword_parameters.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
STINNER Victor added the comment: We are close to Python 3.4 final, so what is the status of this issue? I don't see any commit and nothing to cherry-pick in Larry's 3.4.0 repository. -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Martin v. Löwis added the comment: Since there is no consensus on how to resolve this issue, I'm dropping the release-critical status for it; people should now consider whether a future agreed-upon solution could apply to 3.4.1 or just to 3.5. -- priority: release blocker - normal ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Martin v. Löwis added the comment: Serhiy: the patch is incomplete; it lacks test cases. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Martin v. Löwis added the comment: The patch sre_deprecate_pattern_keyword-3.4.patch looks good to me. I *think* that Larry has pre-approved it for 3.4. If it is applied, and if people still think that 2.7 and 3.3 need to be changed, the release-critical status should be removed from the issue. -- nosy: +loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: The disadvantage of sre_deprecate_pattern_keyword-3.4.patch is that it creates false signature for SRE_Pattern.match(). Default value of first argument is exposed as None, but actually this parameter is mandatory and None is not valid value for it. I afraid the only way to get rid of false signature (and keep backward compatibility) is to revert converting to Argument Clinic. And here is a patch which do this. -- Added file: http://bugs.python.org/file34280/sre_deprecate_pattern_keyword-3.4_2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___diff -r c47cc6351ce7 Modules/_sre.c --- a/Modules/_sre.cMon Mar 03 21:19:19 2014 +0200 +++ b/Modules/_sre.cMon Mar 03 23:11:13 2014 +0200 @@ -526,59 +526,49 @@ return sre_ucs4_search(state, pattern); } -/*[clinic input] -module _sre -class _sre.SRE_Pattern PatternObject * Pattern_Type - -_sre.SRE_Pattern.match as pattern_match - -pattern: object -pos: Py_ssize_t = 0 -endpos: Py_ssize_t(c_default=PY_SSIZE_T_MAX) = sys.maxsize - -Matches zero or more characters at the beginning of the string. -[clinic start generated code]*/ - -PyDoc_STRVAR(pattern_match__doc__, -match($self, /, pattern, pos=0, endpos=sys.maxsize)\n ---\n -\n -Matches zero or more characters at the beginning of the string.); - -#define PATTERN_MATCH_METHODDEF\ -{match, (PyCFunction)pattern_match, METH_VARARGS|METH_KEYWORDS, pattern_match__doc__}, - static PyObject * -pattern_match_impl(PatternObject *self, PyObject *pattern, Py_ssize_t pos, Py_ssize_t endpos); +fix_string_param(PyObject *string, PyObject *string2, const char *oldname) +{ +if (string2 != NULL) { +if (string != NULL) { +PyErr_Format(PyExc_TypeError, + Argument given by name ('%s') and position (1), + oldname); +return NULL; +} +if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + The '%s' keyword parameter name is deprecated. + Use 'string' instead., oldname) 0) +return NULL; +return string2; +} +if (string == NULL) { +PyErr_SetString(PyExc_TypeError, +Required argument 'string' (pos 1) not found); +return NULL; +} +return string; +} static PyObject * pattern_match(PatternObject *self, PyObject *args, PyObject *kwargs) { -PyObject *return_value = NULL; -static char *_keywords[] = {pattern, pos, endpos, NULL}; -PyObject *pattern; +static char *_keywords[] = {string, pos, endpos, pattern, NULL}; +PyObject *string = NULL; Py_ssize_t pos = 0; Py_ssize_t endpos = PY_SSIZE_T_MAX; - -if (!PyArg_ParseTupleAndKeywords(args, kwargs, -O|nn:match, _keywords, -pattern, pos, endpos)) -goto exit; -return_value = pattern_match_impl(self, pattern, pos, endpos); - -exit: -return return_value; -} - -static PyObject * -pattern_match_impl(PatternObject *self, PyObject *pattern, Py_ssize_t pos, Py_ssize_t endpos) -/*[clinic end generated code: output=1528eafdb8b025ad input=26f9fd31befe46b9]*/ -{ +PyObject *pattern = NULL; SRE_STATE state; Py_ssize_t status; -PyObject *string; - -string = state_init(state, (PatternObject *)self, pattern, pos, endpos); + +if (!PyArg_ParseTupleAndKeywords(args, kwargs, +|Onn$O:match, _keywords, +string, pos, endpos, pattern)) +return NULL; +string = fix_string_param(string, pattern, pattern); +if (!string) +return NULL; +string = state_init(state, (PatternObject *)self, string, pos, endpos); if (!string) return NULL; @@ -603,12 +593,16 @@ SRE_STATE state; Py_ssize_t status; -PyObject* string; +PyObject *string = NULL, *string2 = NULL; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; -static char* kwlist[] = { pattern, pos, endpos, NULL }; -if (!PyArg_ParseTupleAndKeywords(args, kw, O|nn:fullmatch, kwlist, - string, start, end)) +static char* kwlist[] = { string, pos, endpos, pattern, NULL }; +if (!PyArg_ParseTupleAndKeywords(args, kw, |Onn$O:fullmatch, kwlist, + string, start, end, string2)) +return NULL; + +string = fix_string_param(string, string2, pattern); +if (!string) return NULL; string = state_init(state, self, string, start, end); @@ -637,12 +631,16 @@ SRE_STATE state; Py_ssize_t status; -PyObject* string; +PyObject *string = NULL, *string2 = NULL; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; -static char* kwlist[] = { pattern, pos, endpos, NULL }; -if (!PyArg_ParseTupleAndKeywords(args, kw, O|nn:search, kwlist, -
[issue20283] Wrong keyword parameter name in regex pattern methods
Larry Hastings added the comment: Why can't you remove the = NULL from the Clinic input for string? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: Why can't you remove the = NULL from the Clinic input for string? Because this will prohibit the use of pattern as keyword argument. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: Here is a patch with the show_in_signature hack for 3.4. -- priority: normal - release blocker Added file: http://bugs.python.org/file34216/sre_deprecate_pattern_keyword-3.4.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Larry Hastings added the comment: Use #3. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Larry Hastings added the comment: pattern should be keyword-only, and if used the function should generate a DeprecationWarning. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: Larry, so what is your decision? 1. Apply the hard patch and then convert Modules/_sre.c to use Argument Clinic (issue20148). 2. Revert converted match() method, apply the soft patch, and delay applying of the hard patch and then converting to use Argument Clinic to 3.5. Applying the soft patch and then the hard patch will cause more source churn than just applying the hard patch. 3. Use show_in_signature hack. I don't like this, it looks ugly and adds too much source churn. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: The patch did not upload correctly. Oh, sorry. Here is correct patch. I propose to apply soft patch (which preserves support for old keyword parameter name) to 2.7 and 3.3, and apply hard patch (which just renames keyword parameter name) to 3.4. Or we can just apply hard patch (it's much simpler) to all versions. -- nosy: +benjamin.peterson, georg.brandl, larry Added file: http://bugs.python.org/file33721/sre_deprecate_pattern_keyword.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Terry J. Reedy tjre...@udel.edu: Removed file: http://bugs.python.org/file33705/sre_deprecate_pattern_keyword.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Georg Brandl added the comment: For 3.3 I prefer the soft patch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Larry Hastings added the comment: Georg: you're accepting this patch into 3.3? I'm surprised. I would only want the soft approach. But I haven't said yes yet. I want to discuss it a little more. (Hey, it's python core dev. Discussing things endlessly is our job.) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: If you want the soft approach, then you should revert your changes to _sre.SRE_Pattern.match. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Larry Hastings added the comment: You can do it, if I accept the patch for 3.4. There's no point in doing it in two stages. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Larry Hastings added the comment: Alternatively, we could use this cheap hack: /*[python input] class hidden_object_converter(object_converter): show_in_signature = False [python start generated code]*/ /*[clinic input] module _sre class _sre.SRE_Pattern PatternObject * Pattern_Type _sre.SRE_Pattern.match as pattern_match string: object pos: Py_ssize_t = 0 endpos: Py_ssize_t(c_default=PY_SSIZE_T_MAX) = sys.maxsize pattern: hidden_object = None ... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: Here is patch for 3.3 which adds alternative parameter name. Now both keyword names are allowed, but deprecation warning is emitted if old keyword name is used. import re p = re.compile('') p.match() Traceback (most recent call last): File stdin, line 1, in module TypeError: Required argument 'string' (pos 1) not found p.match('') _sre.SRE_Match object at 0xb705c598 p.match(string='') _sre.SRE_Match object at 0xb705c720 p.match(pattern='') __main__:1: DeprecationWarning: The 'pattern' keyword parameter name is deprecated. Use 'string' instead. _sre.SRE_Match object at 0xb705c758 p.match('', string='') Traceback (most recent call last): File stdin, line 1, in module TypeError: Argument given by name ('string') and position (1) p.match('', pattern='') Traceback (most recent call last): File stdin, line 1, in module TypeError: Argument given by name ('pattern') and position (1) -- Added file: http://bugs.python.org/file33705/sre_deprecate_pattern_keyword.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Terry J. Reedy added the comment: Great. Old and new both in at least one release, when possible, is best. I should have thought of asking if that would be possible. In this case, I think the (undocumented) old should disappear in 3.5. Since the mistaken 'pattern' name is not documented now, I would not add anything to the doc. I would augment the the warning The 'pattern' keyword parameter name is deprecated. to briefly explain the deprecation and its timing by saying The erroneous and undocumented 'pattern' keyword parameter name is deprecated and will be removed in version 3.5. The patch did not upload correctly. I just see Modules/_sre.c | 64 [32m+++[0;39m[36m!![0;39m 1 file changed, 44 insertions(+), 20 modifications(!) when I open it in a new Firefox tab. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Tal Einat talei...@gmail.com: -- nosy: +taleinat ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Serhiy Storchaka added the comment: Actually, several other methods also have wrong parameter name, source instead of string. -- stage: needs patch - patch review Added file: http://bugs.python.org/file33598/sre_pattern_string_keyword.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Serhiy Storchaka storch...@gmail.com: Removed file: http://bugs.python.org/file33509/sre_pattern_string_keyword.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Serhiy Storchaka storch...@gmail.com: -- nosy: +mrabarnett ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Terry J. Reedy added the comment: If no one else pipes up here, perhaps ask on pydef about changing C names to match documented names. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Serhiy Storchaka storch...@gmail.com: -- keywords: +patch Added file: http://bugs.python.org/file33508/sre_pattern_string_keyword.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Serhiy Storchaka storch...@gmail.com: Removed file: http://bugs.python.org/file33508/sre_pattern_string_keyword.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Changes by Serhiy Storchaka storch...@gmail.com: Added file: http://bugs.python.org/file33509/sre_pattern_string_keyword.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
Terry J. Reedy added the comment: How nasty. I agree that this is a code bug. Unfortunately in this case, the C code does keyword matching of arguments and 'corrects' the doc for anyone who tries 'string='. pat.search(string='xabc', pos=1) Traceback (most recent call last): File pyshell#6, line 1, in module pat.search(string='xabc', pos=1) TypeError: Required argument 'pattern' (pos 1) not found pat.search(pattern='xabc', pos=1) _sre.SRE_Match object; span=(1, 4), match='abc' I think we should only change this in 3.4 (and should do so in 3.4). -- nosy: +terry.reedy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20283] Wrong keyword parameter name in regex pattern methods
New submission from Serhiy Storchaka: Documented (in docstring and in ReST documentation) signatures of the match, search and (since 3.4) fullmatch methods of regex pattern object are: match(string[, pos[, endpos]]) search(string[, pos[, endpos]]) fullmatch(string[, pos[, endpos]]) However in implementation the first keyword argument by mistake named pattern. This looks as nonsense. The pattern is object itself, and first argument is a string. First arguments in other methods (split, findall, etc) named string, and module-level functions have both pattern and string parameters: match(pattern, string, flags=0) search(pattern, string, flags=0) I think we should fix this mistake. The pattern name is obviously wrong and is not match the documentation. -- components: Library (Lib) messages: 208311 nosy: ezio.melotti, pitrou, serhiy.storchaka priority: normal severity: normal stage: needs patch status: open title: Wrong keyword parameter name in regex pattern methods type: behavior versions: Python 2.7, Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20283 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com