[issue30072] re function: convert count and flags parameters to keyword-only?

STINNER Victor report at bugs.python.org
Fri Apr 14 08:36:04 EDT 2017


New submission from STINNER Victor:

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!

----------
components: Library (Lib)
messages: 291650
nosy: haypo, serhiy.storchaka
priority: normal
severity: normal
status: open
title: re function: convert count and flags parameters to keyword-only?
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30072>
_______________________________________


More information about the Python-bugs-list mailing list