You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
re functions: convert count and flags parameters to keyword-only? #74258
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 bpo-30067 for a recent bug in the Python stdlib!
changed the title [-]re function: convert count and flags parameters to keyword-only?[/-][+]re functions: convert count and flags parameters to keyword-only?[/+]on Apr 14, 2017
Activity
vstinner commentedon Apr 14, 2017
The re API seems commonly misused. Example passing a re flag to re.sub():
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 bpo-30067 for a recent bug in the Python stdlib!
[-]re function: convert count and flags parameters to keyword-only?[/-][+]re functions: convert count and flags parameters to keyword-only?[/+]serhiy-storchaka commentedon Apr 14, 2017
This is a duplicate of bpo-11957.