"import gtk" changes sys.getdefaultencoding()

Bug #27112 reported by Andrew Bennetts
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
PyGTK
Won't Fix
Medium
pygtk (Ubuntu)
Invalid
Medium
Sebastien Bacher

Bug Description

>>> import sys
>>> print sys.getdefaultencoding()
'ascii'
>>> import gtk
>>> print sys.getdefaultencoding()
'utf-8'

This is bad. It is generally a bad idea for a library to change global state
that may break other libraries; it's worse that it does this as a side-effect of
merely being imported. sys.setdefaultencoding is also generally considered a
misfeature by the Python developers, and changing the default encoding from
'ascii' (except perhaps to 'undefined') is asking for potential bugs to be
hidden, rather than raising exceptions when you'd expect. There's a reason
sys.setdefaultencoding is not accessible by default.

http://bugzilla.gnome.org/show_bug.cgi?id=132040: http://bugzilla.gnome.org/show_bug.cgi?id=132040

Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks for your bug. I've forwarded it upstream:
http://bugzilla.gnome.org/show_bug.cgi?id=324323

Revision history for this message
Sebastien Bacher (seb128) wrote :

Already known as http://bugzilla.gnome.org/show_bug.cgi?id=132040 upstream with
some comments on it

Changed in pygtk:
status: Unconfirmed → Confirmed
status: Unconfirmed → Confirmed
Revision history for this message
Johan Dahlin (jdahlin-deactivatedaccount) wrote :

It's not really possible to fix this, since the whole gtk+ stack requires all strings to be encoded in utf-8.
And also, it's part of the PyGTK API already, plenty of applications are going to break if it was removed.

Revision history for this message
Kyle Brooks (kyle-brooks) wrote :

Can't be fixed due to compatibility problems (see Johan Dahlin's recent comment): rejected

Changed in pygtk:
status: Confirmed → Rejected
Changed in pygtk:
status: Unconfirmed → Confirmed
Changed in pygtk:
importance: Unknown → Medium
Revision history for this message
Curtis Hovey (sinzui) wrote :

I believe this issue is solved with modern pygtk using
    from gi.repository import Gtk
Which seems to avoid changing the default encoding.

Revision history for this message
Guilherme Salgado (salgado) wrote :

Indeed, if you import gi.repository.Gtk it won't, but it still does if you import pango.

Changed in pygtk:
status: Confirmed → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.