[New-bugs-announce] [issue28905] re.sub appears not to check count optional argument for integerness

Danny Yoo report at bugs.python.org
Thu Dec 8 12:02:58 EST 2016


New submission from Danny Yoo:

This comes from diagnosing a beginner's question on Python-tutor.

https://mail.python.org/pipermail/tutor/2016-December/110066.html

It appears that re.sub is not checking whether the count argument is integer or not, and silently accepts a nonsensical argument.  For example:


>>> import re
>>> s = "AAAcBBB\nAAAdBBB"
>>> print(re.sub(r'^AAA', "aaa", s, re.MULTILINE))
aaacBBB
AAAdBBB


Of course, the user intended to pass re.MULTILINE to flags, not to count, but the fact that this isn't raising a TypeError is error-prone.

----------
components: Library (Lib)
messages: 282719
nosy: Danny Yoo
priority: normal
severity: normal
status: open
title: re.sub appears not to check count optional argument for integerness
type: behavior
versions: Python 3.4

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


More information about the New-bugs-announce mailing list