Serhiy Storchaka added the comment:

Here are two alternative patches. The first patch checks if count or maxsplit 
arguments are re.RegexFlag and raise TypeError if it is true. This makes 
misusing flags fail fast. The second patch deprecates passing count and 
maxsplit arguments as positional arguments. This imposes your to change your 
code (even if it is valid now) and makes hard misusing flags.

Unfortunately both ways slow down calling functions.

$ ./python -m perf timeit -s "import re" -- 're.split(":", ":a:b::c", 2)'

unpatched:                   Median +- std dev: 2.73 us +- 0.09 us
check_flags_type:            Median +- std dev: 3.74 us +- 0.09 us
deprecate_positional_count:  Median +- std dev: 10.6 us +- 0.2 us

$ ./python -m perf timeit -s "import re" -- 're.split(":", ":a:b::c", 
maxsplit=2)'

unpatched:                   Median +- std dev: 2.78 us +- 0.07 us
check_flags_type:            Median +- std dev: 3.75 us +- 0.10 us
deprecate_positional_count:  Median +- std dev: 2.86 us +- 0.08 us

----------
stage:  -> patch review
versions: +Python 3.6, Python 3.7 -Python 3.5
Added file: http://bugs.python.org/file44825/re_check_flags_type.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11957>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to