This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: re functions: convert count and flags parameters to keyword-only?
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: re.sub confusion between count and flags args
View: 11957
Assigned To: Nosy List: serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2017-04-14 12:36 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg291650 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-04-14 12:36
The re API seems commonly misused. Example passing a re flag to re.sub():

>>> re.sub("A", "B", "ahah", re.I)
'ahah'

No error, no warning, but it doesn't work. Oh, sub has 5 paramters, no 4...

I suggest to convert count and flags to keyword-only parameters. To not break the world, especially legit code passing the count parameter as a position argument, an option is to have a deprecation period if these two parameters are passed a positional-only parameter.

--

Another option would be to rely on the fact that re flags are now enums instead of raw integers, and so add basic type check...

Is there are risk of applications using re flags serialized by pickle from Pyhon < 3.6 and so getting integers?

Maybe the check should only be done if flags are passing as positional-only argument... but the implementation of such check seems may be overkill for such simple and performance-critical function, no?

See issue #30067 for a recent bug in the Python stdlib!
msg291653 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-14 12:45
This is a duplicate of issue11957.
History
Date User Action Args
2022-04-11 14:58:45adminsetgithub: 74258
2017-04-14 12:45:06serhiy.storchakasetstatus: open -> closed
superseder: re.sub confusion between count and flags args
messages: + msg291653

resolution: duplicate
stage: resolved
2017-04-14 12:36:28vstinnersettitle: re function: convert count and flags parameters to keyword-only? -> re functions: convert count and flags parameters to keyword-only?
2017-04-14 12:36:04vstinnercreate