Putting _() into builtins causes trouble with doctests
|Reported by:||Malcolm Tredinnick||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
We install a function called
_() as an alias for
__builtins__ so that we don't have to import everywhere we want to translate strings.
The Python interactive shell uses the
_ variable to store the most recent result. Any doctests run in the same sort of environment as the interactive shell and so this variable gets nuked. If a class has doctests and uses translation functionality, chaos ensues.
One solution is to import
gettext() and alias it to
_() in each modules' scope. A little awkward but not inherently bad. Maybe there's another solution I haven't thought of yet, though.
Original problem description in this django-users thread.