[Python-Dev] Breaking undocumented API
hrvoje.niksic at avl.com
Wed Nov 10 13:23:35 CET 2010
On 11/10/2010 05:12 AM, Stephen J. Turnbull wrote:
> But these identifiers will appear at the module level, not global, no?
> Otherwise this technique couldn't be used. I don't really understand
> what Tres is talking about when he writes "modules that expect to be
> imported this way". The *imported* module shouldn't care, no?
I think he's referring to the choice of identifiers, and the usage
examples given in the documentation and tutorials. For example, in the
original PyGTK, all identifiers included "Gtk" in the name, so it made
sense to write from pygtk import * so you could spell GtkWindow as
GtkWindow rather than the redundant pygtk.GtkWindow. In that sense the
module writer "expected" to be imported this way, although you are right
that it doesn't the least bit matter for the correct operation of the
module itself. For GTK 2 PyGTK switch to "gtk.Window", which
effectively removes the temptation to import * from the module.
There are other examples of that school, most notably ctypes, but also
Tkinter and the python2 threading module. Fortunately it has become
much less popular in the last ~5 years of Python history.
More information about the Python-Dev