Putting _() into builtins causes trouble with doctests
|Reported by:||mtredinnick||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 gettext() into __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.
Change History (11)
comment:2 Changed 9 years ago by Michael Radziej <mir@…>
- Triage Stage changed from Unreviewed to Design decision needed
comment:8 Changed 8 years ago by russellm
- Triage Stage changed from Design decision needed to Accepted
comment:9 Changed 8 years ago by Simon G. <dev@…>
- Resolution set to fixed
- Status changed from new to closed
comment:10 Changed 8 years ago by mtredinnick
- Resolution fixed deleted
- Status changed from closed to reopened