At 01:47 PM 10/13/2005 +1300, Greg Ewing wrote:
>I just tried to implement an autoloader using a technique
>I'm sure I used in an earlier Python version, but it no
>longer seems to be allowed.
>
>I'm trying to change the __class__ of a newly-imported
>module to a subclass of types.ModuleType, but I'm getting
>
>    TypeError: __class__ assignment: only for heap types
>
>Have the rules concerning assignent to __class__ been
>made more restrictive recently?

It happened in Python 2.3, actually.  The best way to work around this is 
to add an instance of your subclass to sys.modules *first*, then call 
reload() on it to make the normal import process work.  PEAK uses this to 
implement lazy loading.

Actually, for your purposes, you might be able to just replace the module 
object and copy its contents to the new module's dictionary.

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to