[Python-ideas] Idea to support lazy loaded names.
Steven D'Aprano
steve at pearwood.info
Tue Oct 7 06:11:13 CEST 2014
On Mon, Oct 06, 2014 at 11:51:45PM -0400, Terry Reedy wrote:
> On 10/6/2014 11:30 PM, Steven D'Aprano wrote:
[...]
> >This is relevant because modules are instances, and module attributes
> >live in the instance __dict__.
>
> So a 'solution' might be to make modules be instances (but with no
> __new__ or __init__) of a module metaclass, so that module dicts could
> act like class dicts with respect to descriptors. I have no idea how
> much code this would break ;-).
Probably lots :-)
It's not common to write something like this outside of a class:
x = property(some_function)
but if you did, you would normally expect lookups on x to return the
property object itself, not call the __get__ method. That's what happens
now, and so by backward compatibility that can't change.
More importantly, defining top-level functions is ubiquitous in Python
code. And functions obey the descriptor protocol! That's how functions
magically turn into methods when put inside a class. So if modules
called __get__ by default, every single function lookup would break.
That would be bad.
So any change to the behaviour of module lookups would need to be
opt-in.
--
Steven
More information about the Python-ideas
mailing list