[Python-Dev] _PyUnicode_CheckConsistency() too strict?

Paul Moore p.f.moore at gmail.com
Mon Feb 3 17:38:35 CET 2014


On 3 February 2014 16:10, Phil Thompson <phil at riverbankcomputing.com> wrote:
> That doesn't answer my original question, that just works around the use
> case I presented.
>
> To restate...
>
> Why is a Latin-1 string considered inconsistent just because it doesn't
> happen to contain any characters in the range 128-255?

Butting in here (sorry) but I thought what Victor was trying to say is
that being able to say that a string marked as Latin1 "kind"
definitely has characters >127 allows the code to optimise some tests
(for example, two strings cannot be equal if their kinds differ).

Obviously, requiring this kind of constraint makes it somewhat harder
for user code to construct string objects that conform to the spec.
That's why the PyUnicode_FromKindAndData function has the convenience
feature of doing the check and setting the kind correctly for you -
you should use that rather than trying to get the details right
yourself..

Paul.


More information about the Python-Dev mailing list