[Python-Dev] Fwd: Problem withthe API for str.rpartition()

Barry Warsaw barry at python.org
Tue Sep 5 19:26:15 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sep 5, 2006, at 1:10 PM, Raymond Hettinger wrote:

>> This change looks wrong:
>>
>> PyDoc_STRVAR(rpartition__doc__,
>> -"S.rpartition(sep) -> (head, sep, tail)\n\
>> +"S.rpartition(sep) -> (tail, sep, head)\n\
>>
>> It looks like the code itself does the right thing, but I wasn't  
>> quite
>> confident of that.
>>
> It is correct.  There may be some confusion in terminology.  Head and
> tail do not mean left-side or right-side. Instead, they refer to the
> "small part chopped-off" and "the rest that is still choppable". Think
> of head and tail in the sense of car and cdr.
>
> A post-condition invariant for both str.partition() and  
> str.rpartition() is:
>
>     assert sep not in head
>
> For non-looping cases, users will likely to use different variable  
> names
> when they unpack the tuple:
>
>    left, middle, right = s.rpartition(p)
>
> But when they perform multiple partitions, the "tail" or "rest"
> terminology is more appropriate for the part of the string that may
> still contain separators.

ISTM this is just begging for newbie (and maybe not-so-newbie)  
confusion.  Why not just document both as returning (left, sep,  
right) which seems the most obvious description of what the methods  
return?

- -Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRP2zPHEjvBPtnXfVAQKpvQP/X1Vg9G4gZLl9R7/fnevmfeszTbqVk1Bq
V7aXYm5pTFiD27cKV2e7MKZPifob6Pg8NPjsvAh6jZU5Uj0BUQhIwgDXZpcivsTM
MykyPz8oVpSLRhu5xfYU1IZjbogoKfPQ04FkqWgtM2QUqKjiLcvwzPnzLNLVxx9r
v2LplvrqJyc=
=Tckf
-----END PGP SIGNATURE-----


More information about the Python-Dev mailing list