[Python-ideas] Extend module objects to support properties
Nick Coghlan
ncoghlan at gmail.com
Wed Jan 30 10:54:18 CET 2013
On Wed, Jan 30, 2013 at 11:06 AM, Larry Hastings <larry at hastings.org> wrote:
>
>
> Properties are a wonderful facility. But they only work on conventional
> objects. Specifically, they *don't* work on module objects. It would be
> nice to extend module objects so properties worked there too.
As MAL notes, the issues with such an approach are:
- code executed at module scope
- code in inner scopes that uses "global"
- code that uses globals()
- code that directly modifies a module's __dict__
There is too much code that expects to be able to modify a module's
namespace directly without going through the attribute access
machinery.
However, a slightly more practical suggestion might be:
1. Officially bless the practice of placing class instances in
sys.modules (currently this is tolerated, since it's the only way to
manage things like lazy module loading, but not officially recommended
as the way to achieve "module properties")
2. Change sys from a module object to an ordinary class instance
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list