[issue5416] str.replace does strange things when given a negative count

Daniel Diniz report at bugs.python.org
Wed Mar 4 15:56:10 CET 2009


Daniel Diniz <ajaksu at gmail.com> added the comment:

Confirmed in trunk and py3k. Changing to RFE, set it to behavior if you
disagree.

Python 2.4 does return "" for str.replace("", "", "asdf", -1), the
change happened in rev46226, with the effbot adding this snippet (by
Andrew Dalke?):

      if (maxcount < 0) {
             maxcount = PY_SSIZE_T_MAX;
      } else if (maxcount == 0 || PyString_GET_SIZE(self) == 0) {
           /* nothing to do; return the original string */
           return return_self(self);
      }


I'm not sure the current behavior can be considered better than what
David proposes, but I also wonder whether it matters at all.

----------
nosy: +ajaksu2
stage:  -> test needed
type:  -> feature request
versions: +Python 2.7, Python 3.1 -Python 2.5

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


More information about the Python-bugs-list mailing list