Incorrect title case?

John Machin sjmachin at
Sat Jan 17 02:58:39 CET 2009

On Jan 17, 9:07 am, MRAB <goo... at> wrote:
> Python 2.6.1
> I've just found that the following 4 Unicode characters/codepoints don't
> behave as I'd expect: Dž (U+01C5), Lj (U+01C8), Nj (U+01CB), Dz (U+01F2).
> For example, u"\u01C5".istitle() returns True and
> unicodedata.category(u"\u01C5") returns "Lt", but u"\u01C5".title()
> returns u'\u01C4', which is the uppercase equivalent. Are these mistakes
> in the Unicode database?

Doesn't look like it. AFAICT it's a mistake in Objects/unicodetype.c,
function _PyUnicode_ToTitlecase.


The code that says:
    if (ctype->title)
        delta = ctype->title;
	delta = ctype->upper;
should IMHO merely be:
    delta = ctype->title;

A value of zero for ctype->title should be interpreted simply as the
offset to add to the ordinal, as it is in the sibling _PyUnicode_To
(Upper|Lower)case functions. See also Tools/unicode/
which treats upper, lower and title identically when preparing the
tables used by those 3 functions.

AFAICT making that change will fix the problem for those four
characters and not ruin any others.

The error that you noticed occurs as far back as I've looked (2.1) and
also occurs in 3.0.


More information about the Python-list mailing list