Metaclass with name overloading.

Jacek Generowicz jacek.generowicz at
Mon Sep 27 13:33:33 CEST 2004

I would like to write a metaclass which would allow me to overload
names in the definition of its instances, like this

class Foo(object):

    __metaclass__ = OverloadingClass

    att = 1
    att = 3

    def meth(self):

    def meth(self, arg):
        return arg

I would then like the dictionary received by OverloadingClass.__new__
to look something like this:

{'att': (1,3),
 'meth: (<function meth at 0x4018e56c>, <function meth at 0x4018e80c>) }

IOW, each name bound in the class definition should have associated
with it, a tuple containing all the objects which were bound to that
name, rather merely keeping the most recent binding for any given

I was wondering whether it would be possible to achieve this by
forcing Python to use some dicitonary proxy (which accumulates values,
rather that keeping just the last value to be associated with a key),
instead of dict, when executing the class definiton?

Is something like this at all possible in pure Python? or does in
require fiddling around in the guts of the parser?

More information about the Python-list mailing list