[Python-3000] PEP 3137 plan of attack

Guido van Rossum guido at python.org
Wed Oct 10 23:06:33 CEST 2007


On 10/10/07, Christian Heimes <lists at cheimes.de> wrote:
> I've a question about one point. The PEP states "They accept anything
> that implements the PEP 3118 buffer API for bytes arguments, and return
> the same type as the object whose method is called ("self")". Which
> types do implement the buffer API? PyString, PyBytes but not PyUnicode?

Plus some other standard types, like memoryview and array.array.
Plus certain extension types, like numpy arrays.

> For now the PyString takes PyUnicode objects are argument and vice versa
> but PyBytes doesn't take unicode. Do I understand correctly that
> PyString must not accept PyUnicode?

Correct.

> >>> b"abc".count("b")
> 1

This is a bug.

> >>> "abc".count(b"b")
> 1

This too.

> >> buffer(b"abc").count("b")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> SystemError: can't use str as char buffer

What is buffer? Are you using an old version of the tree (where it was
an object like memoryview) or a patched version where you've already
renamed str8 to buffer?

Anyway, str8().count(str()) should raise TypeError.

> >>> buffer(b"abc").count(b"b")
> 1

Same question. Once the PEP is completely implemented, this should be correct.

> I've a patch that renames PyString -> bytes and PyByte -> buffer while
> keeping str8 as an alias for bytes until str8 is removed. It's based on
> Alexandres patch which itself is partly based on my patch. It breaks a
> hell of a lot but it could give you a head start.

The rename is trivial. It's fixing all the unit tests that matters.

> >>> b''
> b''
> >>> type(b'')
> <type 'bytes'>
> >>> type(b'') is str8
> True
> >>> type(b'') is bytes
> True
> >>> type(buffer(b''))
> <type 'buffer'>
>
> I'll keep working on the patch.

Cool.

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


More information about the Python-3000 mailing list