On 16 July 2013 12:20, Guido van Rossum <gu...@python.org> wrote:
> On Mon, Jul 15, 2013 at 7:03 PM, Stephen J. Turnbull <step...@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   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to