[Python-Dev] _PyUnicode_CheckConsistency() too strict?

Phil Thompson phil at riverbankcomputing.com
Mon Feb 3 16:13:21 CET 2014

_PyUnicode_CheckConsistency() checks that the contents of the string 
matches the _KIND of the string. However it does this in a very strict 
manner, ie. that the contents *exactly* match the _KIND rather than just 
detecting an inconsistency between the contents and the _KIND.

For example, a string created with a maxchar of 255 (ie. a Latin-1 
string) must contain at least one character in the range 128-255 
otherwise you get an assertion failure.

As it stands, when converting Latin-1 strings in my C extension module 
I must first check each character and specify a maxchar of 127 if the 
strings happens to only contain ASCII characters.

What is the reasoning behind the checks being so strict?


More information about the Python-Dev mailing list