[wingide-users] redefinition of _

Wingware Support support at wingware.com
Thu Oct 27 13:03:50 MDT 2011

On 10/27/11 12:06 PM, David Hughes wrote:
> I keep tripping over this one :
> When Wing stops at a breakpoint the name _ (single underscore) gets 
> (re)defined to hold the result of the last executed expression in the 
> debug probe like in any Python interactive session. Unfortunately the 
> internationalisation (i18n) module lib/gettext.py installs a 
> *function* _() in the Python builtins namespace to hold the 
> candidate-for-translation strings. So, on resuming from a breakpoint 
> an exception gets raised the next time a call to _() is encountered.
> Is there a user workaround for this? If not, would it be possible for 
> you to save and restore the original definition on breakpoint entry 
> and exit?

There isn't a work-around for this right now and it's a bit dubious to 
install _ into __builtins__ since, as you note, _ there is already in 
use by Python's internals in an interactive session.  An odd design I've 
always wondered at but apparently this persists even in Python 3.2.

I'd recommend avoiding calling getttext.install() and setting explicitly 
_ instead in some other way.  We just do the following sort of thing in 
each file:

import gettext
_ = gettext.translation('src_pref', fallback = 1).ugettext

I've just checked in a hack that saves/restores __builtins__._ if it's a 
method of gettext.NullTranslations or a descendent, but I don't know if 
this will make it into the product.  It's somewhat dubious, although 
perhaps we'll leave it in given that gettext.install still works like 
this in Python 3.  I'd still recommend avoiding gettext.install() since 
other shells will still have issues w/ this.


Stephan Deibel
Wingware | Python IDE
Advancing Software Development


More information about the wingide-users mailing list