[Python-Dev] Misc re.match() complaint
Nick Coghlan
ncoghlan at gmail.com
Tue Jul 16 05:03:29 CEST 2013
On 16 July 2013 12:20, Guido van Rossum <guido at python.org> wrote:
> On Mon, Jul 15, 2013 at 7:03 PM, Stephen J. Turnbull <stephen at xemacs.org> wrote:
>> Or is this something deeper, that a group *is* a new object in
>> principle?
>
> No, I just think of it as returning "a string" and I think it's most
> useful if that is always an immutable object, even if the target
> string is some other bytes buffer.
>
> FWIW, it feels as if the change in behavior is probably just due to
> how slices work.
I took a look at the way the 2.7 re code works, and the change does
indeed appear to be due to the difference in the way slices work for
buffer and memoryview objects:
Slicing a buffer creates an 8-bit string:
>>> buffer(b"abc")[0:1]
'a'
Slicing a memoryview creates another memoryview:
>>> memoryview(b"abc")[0:1]
<memory at 0x7f3320541b98>
Unfortunately, memoryview doesn't currently allow subclasses, so it
isn't easy to create a derivative that coerces to bytes on slicing :(
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list