Metaclass discussons

Gustavo Niemeyer niemeyer at conectiva.com
Fri Aug 22 15:30:39 EDT 2003


Hi everyone!

I was just part of a small discussion concerning metaclass features on
Python, and one limitation that was appointed was the inability to
redefine metaclasses on existent code. Than I thought it was a good
way to explore some more the metaclass concepts.. 

Basically, people were arguing that there are some uses for that, based
on plugging new knowledge on existent classes and instances. Without
complaining too much about usage issues, I started looking for ways to
dismiss that limitation.

Without yet considering interpreter hacks, that's what I had as a first
solution (a very limited one, I must admit):

class M(type): pass
__metaclass__ = M
class object:
    __metaclass__ = M
execfile("somemodule.py", globals(), locals())

Can you imagine any alternative which is not based on the same concept
(executing the module code on a hacked context)?

-- 
Gustavo Niemeyer
http://niemeyer.net





More information about the Python-list mailing list