[PyKDE] Auto-connecting Slots

Giovanni Bajo rasky at develer.com
Sat Jan 28 15:26:05 GMT 2006

Jim Bublitz <jbublitz at nwinternet.com> wrote:

> I don't believe Phil is imposing anything as far as coding style beyond
> Python already requires with methods/functions imported from modules.
> 'signature' has to be part of the QtCore module or some other module. The
> alternative to "polluting" the QtCore namespace would be to give signature
> it's own namespace, but I don't think "QtCore.PyQt.signature" or something
> similar is more attractive or intuitive. Where else are you going to
> it from and how else are you going to specify the module being imported
> from?

> Personally, I'm not sympathetic to users of the "from module import *"
> construct, although I'm sure we all do it at one time or another (although
> can't think of any place I've used it recently). As they say, "explicit is
> better than implicit", and sooner or later I would bet most people who use
> modules beyond what Python supplies and use 'import *' all over run into
> name clashes. Worse, they can be difficult bugs to track down.

I never use "from module import *" for normal modules. But I also try and
achieve consistency in namings to avoid duplications between names within
modules/namespace and namespaces themselves, which is IMO more important.

Qt has its own namespace which is made of a prefix for every public name
(plus full-uppercase names for preprocessor macros like SIGNAL). QWidget
means QtWidget, or Qt::Widget. If they were to move to using C++ namespaces,
I'd rather have Qt::Widget or Q::Widget, but surely *not* Qt::QWidget. The
same applies for PyQt to me. Typing QtCore.QWidget is way way way too
verbose, and it does not provide anything but confusion. Qt.Widget would be
much better and I would be fine. But not Qt.QWidget, *nor* QtCore.QWidget.

Notice that this is not only the case of PyQt, there are similar libraries
with the same issue, and which are *designed* to be used with the "from
module import *" syntax. PyOpenGL comes to mind. Normal code looks like:

from OpenGL.GL import *


You can see a clear "gl" namespace in front of *everything*. Using "import
OpenGL" or "from OpenGL import GL" would cause the code to looks like
"OpenGL.GL.glBegin" or even "GL.glBegin" which feels like a totally useless
duplication to me. People are free to do whatever they want with their code,
but stay assured I *will* complain the day the PyOpenGL guys add a name like
"signature" within their OpenGL.GL module.

So, to repeat, I'm not trying to make everyone change their coding styles or
something. Everybody has its rights to decide how to use PyQt. But surely, I
don't expect PyQt to add new names to its modules which are in contrast with
this convention, and make life harder to those who prefer to use plain Q*
Giovanni Bajo

More information about the PyQt mailing list