Can I turn off implicit Python unicode conversions to find my mixed-strings bugs?

Posted by Tal Weiss on Stack Overflow See other posts from Stack Overflow or by Tal Weiss
Published on 2010-05-17T18:00:04Z Indexed on 2010/05/17 18:20 UTC
Read the original article Hit count: 242

Filed under:
|
|
|

When profiling our code I was surprised to find millions of calls to
C:\Python26\lib\encodings\utf_8.py:15(decode)

I started debugging and found that across our code base there are many small bugs, usually comparing a string to a unicode or adding a sting and a unicode. Python graciously decodes the strings and performs the following operations in unicode.

How kind. But expensive!

I am fluent in unicode, having read Joel Spolsky and Dive Into Python...

I try to keep our code internals in unicode only.

My question - can I turn off this pythonic nice-guy behavior? At least until I find all these bugs and fix them (usually by adding a u'u')?

Some of them are extremely hard to find (a variable that is sometimes a string...).

Python 2.6.5 (and I can't switch to 3.x).

© Stack Overflow or respective owner

Related posts about python

Related posts about unicode