[Python-Dev] Autoloading? (Making Queue.Queue easier to use)
Nick Coghlan
ncoghlan at gmail.com
Mon Oct 17 11:55:13 CEST 2005
Steven Bethard wrote:
> Nick Coghlan wrote:
>> Having module attribute access obey the descriptor protocol (__get__, __set__,
>> __delete__) sounds like a pretty good option to me.
>>
>> It would even be pretty backwards compatible, as I'd be hardpressed to think
>> why anyone would have a descriptor *instance* as a top-level object in a
>> module (descriptor definition, yes, but not an instance).
>
> Aren't all functions descriptors?
So Josh pointed out.
> py> def baz():
> ... print "Evaluating baz!"
> ... return "Module attribute"
> ...
> py> baz()
> Evaluating baz!
> 'Module attribute'
> py> baz.__get__(__import__(__name__), None)
> <bound method ?.baz of <module '__main__' (built-in)>>
> py> baz.__get__(__import__(__name__), None)()
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> TypeError: baz() takes no arguments (1 given)
>
> How would your proposal change the invocation of module-level functions?
It would, alas, break it. And now that I think about it, functions have to
work the way they do, otherwise binding an arbitrary function to a class
variable wouldn't work properly.
So the class descriptor protocol can't be used as is at the module level,
because functions are descriptor instances.
Ah well, another idea runs aground on the harsh rocks of reality.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.blogspot.com
More information about the Python-Dev
mailing list