[Python-ideas] Module __getattr__ [Was: breaking out of module execution]

Jim Jewett jimjjewett at gmail.com
Fri Apr 27 15:31:02 CEST 2012

On Wed, Apr 25, 2012 at 2:35 PM, Matt Joiner <anacrolix at gmail.com> wrote:
> If this is to be done I'd like to see all special methods supported. One of
> particular interest to modules is __getattr__...

For What It's Worth, supporting __setattr__ and __getattr__ is one of
the few reasons that I have considered subclassing modules.

The workarounds of either offering public set_varX and get_varX
functions, or moving configuration to a separate singleton, just feel

Since those module methods would be defined at the far left, I don't
think it would mess up understanding any more than they already do on
regular classes.  (There is always *some* surprise, just because they
are unusual.)

That said, I personally tend to view modules as a special case of
classes, so I wouldn't be shocked if others found it more confusing
than I would -- particularly as to whether or not the module's
__getattr__ would somehow affect the lookup chain for classes defined
within the module.


More information about the Python-ideas mailing list