New submission from Ville Skyttä <ville.sky...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue33585>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to