[Python-Dev] Dynamic module namspaces
Johan Dahlin
jdahlin at async.com.br
Mon Jul 17 15:31:44 CEST 2006
James Y Knight wrote:
>
> On Jul 15, 2006, at 2:38 PM, Johan Dahlin wrote:
>> What I want to ask, is it possible to have a sanctioned way to implement
>> a dynamic module/namespace in python?
>>
>> For instance, it could be implemented to allow you to replace the
>> __dict__ attribute in a module with a user provided object which
>> implements the dictionary protocol.
>
> I'd like this, as well, although my use case is different: I'd like to
> be able to deprecate attributes in a module. That is, if I have:
>
> foo.py:
> SOME_CONSTANT = 5
>
> I'd like to be able to do something such that any time anyone accessed
> foo.SOME_CONSTANT, it'd emit a DeprecationWarning.
Agreed, this would be another nice feature to have.
I've did something similar a time ago for PyGTK aswell, while less elegant
than your proposed solution, it seems that it's working fairly well:
DeprecatedConstant can be found here:
http://cvs.gnome.org/viewcvs/pygtk/gtk/deprecation.py?view=markup
--
Johan Dahlin <jdahlin at async.com.br>
Async Open Source
More information about the Python-Dev
mailing list