[Python-3000] Heaptypes
Thomas Heller
theller at ctypes.org
Wed Jul 11 16:39:00 CEST 2007
Guido van Rossum schrieb:
> There are currently three "string" types, here shown with there repr styles:
>
> - str = 'same as unicode in 2.x'
> - bytes = b'new, mutable list of small ints'
> - str8 = s'same as str in 2.x'
>
> The s'...' notation means it's an 8-bit string (not a bytes array).
> This is not supported in the syntax; it's just used on output. (Use
> str8(b'...') to create one of these.) I'm still hoping to remove this
> type before the release, but it appears to be still necessary so far.
>
> I don't know enouch about ...CallFunction to help you with the rest.
Let me explain it in other words. This code creates a new type:
>>> ht = type("name", (object,), {})
[47054 refs]
>>> ht
<class '__main__.name'>
[47093 refs]
The '__name__' attribute is a (unicode) string:
>>> ht.__name__
'name'
[47121 refs]
>>>
But I can also create a type in this way:
>>> ht = type(str8(b"name"), (object,), {})
[47208 refs]
The __name__ attribute is a str8 instance:
>>> ht.__name__
s'name'
[47236 refs]
Printing the type triggers an assertion:
>>> ht
Assertion failed: obj && PyUnicode_Check(obj), file \svn\py3k-struni\Objects\unicodeobject.c, line 630
C:\svn\py3k-struni\PCbuild>
because parts of the code assume that the '__name__' is a (unicode) string.
Thomas
More information about the Python-3000
mailing list