[issue18468] re.group() should never return a bytearray

Ezio Melotti report at bugs.python.org
Thu Jul 18 15:05:15 CEST 2013


Ezio Melotti added the comment:

I'm not sure it's worth changing it.
As I see it, match/search are supposed to work with str or bytes and they return str/bytes accordingly.  The fact that they work with other bytes-like objects seems to me an undocumented implementation detail people should not rely on.
If they are passing bytes-like object, both the current behavior (return same type) or the new proposed behavior (always return bytes) seem reasonable expectations.

IIUC the advantage of changing the behavior is that it won't keep the target string alive anymore, but on the other hand is not backward compatible and makes things more difficult for people who want the same type back.
If people always want bytes back regardless of the input, they can convert the input or output to bytes explicitly.

----------
components: +Regular Expressions
nosy: +ezio.melotti, mrabarnett

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


More information about the Python-bugs-list mailing list