[Python-3000] Should PyString (new bytes type) accept strings with encoding?

Guido van Rossum guido at python.org
Mon Oct 15 18:49:17 CEST 2007


On 10/15/07, Christian Heimes <lists at cheimes.de> wrote:
> I'm working on the renaming of str8 -> bytes and bytes -> buffer.
> PyBytes (old bytes, new buffer) can take a string together with an
> encoding and an optional error argument:
>
>
> >>> bytes(source="abc", encoding="ascii", errors="replace")
> b'abc'
> >>> str(b"abc", encoding="ascii")
> 'abc'

Correct.

> IMO this should work
> >>> str8("abc", encoding="ascii")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'encoding' is an invalid keyword argument for this function

Yes, this should work. (I thought it already did but was wrong. ;-)

> And this should break with a type error
> >>> str8("abc")
> b'abc'

Correct.

> PyString' constructor doesn't take strings (PyUnicode). I like to add
> the support for strings to it. It makes the API of str, bytes and buffer
> consistent and fixes a *lot* of broken code and tests.

Right.

> Are you confused by the name changes? I'm sometimes confused so I made a
> table:
>
>  c name   |  old  |   new  |  repr
> -------------------------------------------
> PyUnicode | str   |   -    | ''
> PyString  | str8  | bytes  | b''
> PyBytes   | bytes | buffer | buffer(b'')

I'd rewrite this as follows:

C name    | 2.x          | 3.0a1      | 3.0a2               |
----------+--------------+------------+---------------------+
PyUnicode | unicode  u"" | str     "" | str             ""  |
PyString  | str       "" | str8   s"" | bytes           ""  |
PyBytes   | N/A          | bytes  b"" | buffer  buffer(b"") |
----------+--------------+------------+---------------------+

Seems worth adding to the PEP. I'll do that.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20071015/b5013dcf/attachment.htm 


More information about the Python-3000 mailing list