[New-bugs-announce] [issue33585] re.sub calls repl function one time too many for catch-all regex

Ville Skyttä report at bugs.python.org
Sun May 20 09:11:22 EDT 2018


New submission from Ville Skyttä <ville.skytta at iki.fi>:

(I'm fairly certain that the title doesn't describe the actual underlying issue all that well, however it is what I'm seeing so going with that for now.)

Compared to Python 3.6, 3.7 appears to call the repl function for re.sub one time too many, when given a catch-all regex. The extra call is made with a match consisting of an empty string. I think this is quite unexpected, and think it's a bug that I hope could be fixed before 3.7 is out.

Demonstration code:

    import re
    def repl(match):
        print(f"Called with match '{match.group(0)}'")
    re.sub(".*", repl, "foo")

3.6.3 produces the expected output:

    Called with match 'foo'

3.7.0b4+ (current git) demonstrates the extra call:

    Called with match 'foo'
    Called with match ''

----------
messages: 317166
nosy: scop
priority: normal
severity: normal
status: open
title: re.sub calls repl function one time too many for catch-all regex
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33585>
_______________________________________


More information about the New-bugs-announce mailing list