Django

Code

Ticket #2920 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

Putting _() into builtins causes trouble with doctests

Reported by: mtredinnick Assigned to: nobody
Milestone: Component: Testing framework
Version: Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

10/17/06 06:41:27 changed by dave AT avaragado.org

Looks like a dupe of #2734.

01/29/07 00:40:00 changed by Michael Radziej <mir@noris.de>

  • stage changed from Unreviewed to Design decision needed.

marked #2734 as duplicate

02/11/07 00:20:52 changed by russellm

(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.

(follow-up: ↓ 6 ) 02/11/07 17:50:35 changed by mtredinnick

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

04/02/07 05:58:43 changed by mtredinnick

(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 ) 04/02/07 06:03:45 changed by mtredinnick

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.

05/14/07 06:56:20 changed by mtredinnick

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

09/07/07 23:59:47 changed by russellm

  • stage changed from Design decision needed to Accepted.

09/14/07 04:34:00 changed by Simon G. <dev@simon.net.nz>

  • status changed from new to closed.
  • resolution set to fixed.

This seems to be fixed?

09/14/07 06:32:47 changed by mtredinnick

  • status changed from closed to reopened.
  • resolution deleted.

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.

10/21/07 12:14:26 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to fixed.

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

This is backwards incompatible, but easy to work around.


Add/Change #2920 (Putting _() into builtins causes trouble with doctests)




Change Properties
Action