[Twisted-Python] Unicode

Ken Kinder ken at kenkinder.com
Mon Oct 3 20:19:44 EDT 2005

Perhaps like many developers, I came across this surprising bit of code
inside a couple of Twisted's methods:

        if isinstance(data, unicode): # no, really, I mean it
            raise TypeError("Data must be not be unicode")

And of course, I simply removed those lines. But I'm sure if I submit
that patch, a discussion similar to this one would develop, because it's
unlikely that such code would have been accidentally included:


Python library will kindly cast unicode objects to strings when
necessary, as is mentioned in the above thread. It *would* be fair to
say that not implicitly deciding on an encoding type is "taking the high
road" if the behavior of encoding weren't so uniformly explicit and
consistent in Python and its standard library:


(There are more...)

The purpose of Python's unicode type is transparent exchange of string
objects, whether those string objects are of type str or type unicode.
Pretending that isn't so and raising a TypeError is not helpful. I would
urge you to AT LEAST provide a detailed explanation in that error,
explaining the philosophical disagreement you have with Python's
unicode-string conversion behavior and have a flag you can set to
disable that check.

More information about the Twisted-Python mailing list