[Python-3000-checkins] r58773 - in python/branches/py3k-pep3137/Lib: encodings/idna.py encodings/punycode.py string.py test/string_tests.py test/test_xml_etree.py test/test_xml_etree_c.py
Guido van Rossum
guido at python.org
Sat Nov 3 23:39:10 CET 2007
On 11/3/07, Christian Heimes <lists at cheimes.de> wrote:
> Alexandre Vassalotti wrote:
> >> Modified: python/branches/py3k-pep3137/Lib/string.py
> >> ==============================================================================
> >> --- python/branches/py3k-pep3137/Lib/string.py (original)
> >> +++ python/branches/py3k-pep3137/Lib/string.py Fri Nov 2 16:59:04 2007
> >> @@ -53,7 +53,7 @@
> >> raise ValueError("maketrans arguments must have same length")
> >> if not (isinstance(frm, bytes) and isinstance(to, bytes)):
> >> raise TypeError("maketrans arguments must be bytes objects")
> >> - L = bytes(range(256))
> >> + L = buffer(range(256))
> >> for i, c in enumerate(frm):
> >> L[c] = to[i]
> >> return L
> >>
> >
> > Why string.maketrans() was changed to return a buffer object?
>
> The return type was a PyBytes instance before the grant renaming, too. I
> guess you are right. It should return a bytes object.
Hm, but the string module is about *text strings*, not bytes. For text
strings, we don't need maketrans (the new str.translate takes a dict
argument (*)). Maybe it should be a static method on the bytes type
(and also on the buffer type for symmetry)?
(*) Hm, maybe a maketrans() that takes two strings and returns a dict
would be useful, it's a bit more compact than a dict literal.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000-checkins
mailing list