Opened 18 years ago

Closed 17 years ago

#2920 closed defect (fixed)

Putting _() into builtins causes trouble with doctests

Reported by: Malcolm Tredinnick Owned by: nobody
Component: Testing framework Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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:1 by dave AT avaragado.org, 18 years ago

Looks like a dupe of #2734.

comment:2 by Michael Radziej <mir@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

marked #2734 as duplicate

comment:3 by Russell Keith-Magee, 18 years ago

(In [4485]) Refs #2920 -- Replaced implicit uses of _() with explicit imports or calls to gettext(). At some point post 0.96, we need to remove the calls that put _ into the builtins.

comment:4 by Malcolm Tredinnick, 18 years ago

(In [4486]) Revert [4485] in order to fix accidental mod_python breakage. Refs #2920.

comment:5 by Malcolm Tredinnick, 18 years ago

(In [4905]) Delayed the reading of settings.USE_I18N until the first use of the i18n
functions. This solves a few import problems we are seeing. Fixed #3687. Refs #2920.

in reply to:  4 comment:6 by Malcolm Tredinnick, 18 years ago

Replying to mtredinnick:

(In [4486]) Revert [4485] in order to fix accidental mod_python breakage. Refs #2920.

For reference, the problems we were seeing are in this django-users thread. They should be fixed after [4905], so we can move onto part II of this ticket, which is removing _() from builtins.

comment:7 by Malcolm Tredinnick, 18 years ago

(In [5230]) unicode: Replaced all implicit uses of _() from builtins with explicitly
importing ugettext and aliasing it to _. Refs #2920.

comment:8 by Russell Keith-Magee, 17 years ago

Triage Stage: Design decision neededAccepted

comment:9 by Simon G. <dev@…>, 17 years ago

Resolution: fixed
Status: newclosed

This seems to be fixed?

comment:10 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: closedreopened

No it's not fixed. It's only fixed in Django's core because we work around it. Not fixed for everybody else writing tests.

comment:11 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: reopenedclosed

(In [6582]) Fixed #2920 -- Removed _() from builtins.

This is backwards incompatible, but easy to work around.

Note: See TracTickets for help on using tickets.
Back to Top