[Python-3000] Does bytes() need to support bytes(<str>, <encoding>)?

Guido van Rossum guido at python.org
Mon Aug 27 22:38:54 CEST 2007


I'm still working on stricter enforcement of the "don't mix str and
bytes" rule. I'm finding a lot of trivial problems, which are
relatively easy to fix but time-consuming.

While doing this, I realize there are two idioms for converting a str
to bytes: s.encode(e) or bytes(s, e). These have identical results. I
think we can't really drop s.encode(), for symmetry with b.decode().
So is bytes(s, e) redundant?

To make things murkier, str(b, e) is not quite redundant compared to
b.encode(e), since str(b, e) also accepts buffer objects. But this
doesn't apply to bytes(s, e) -- that one *only* accepts str. (NB:
bytes(x) is a different API and accepts a different set of types.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list