[Python-checkins] r51494 - python/branches/p3yk-noslice/Objects/stringobject.c python/branches/p3yk-noslice/Objects/tupleobject.c python/branches/p3yk-noslice/Objects/unicodeobject.c

Thomas Wouters thomas at python.org
Wed Aug 23 15:30:55 CEST 2006


On 8/23/06, Jim Jewett <jimjjewett at gmail.com> wrote:
>
> (1)  I would personally prefer
>
> if (step == 1) {
>     if (start == 0 && ...) {}
>     else {}
> }
>
> I realize that the compiler can do this, but I like flagging "this is
> an odd special case"


Well, they are two separate special cases. I personally prefer to keep them
separate this way, and it reduces indentation level.

(2)  Why the CheckExact?  Is there a promise (even in py3K) that
> constructors won't return a subclass?  I had thought that the question
> was only when/if to *guarantee* that the subclass would be used.  If
> the intent is to guard against subclasses with a different internal
> layout, then it should come before the GET_SIZE macros.


As the checkin message says, those special cases are actually taken from
normal slicing. It's safe for s[:] to return s only for exact instances of
string (and unicode, and tuple) since it's completely equivalent. The same
is not true for subclasses -- it might be, but it doesn't have to be. The
issue isn't memory layout, it's mutability and type. Memory layout should be
the same, anyway -- that's how C-type-subclasses work. There are explicit
checks for this behaviour, by the way.

-- 
Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-checkins/attachments/20060823/d66f6dbf/attachment.htm 


More information about the Python-checkins mailing list