No problem. Metaclasses are confusing, at best.
It's basically an exact copy of UndefinedFunction in
sympy/core/function.py. Assuming that OneQuibitGate is an instance of
Basic (so that its metaclass is ManagedProperties), just have
from sympy.core.core import BasicMeta
from sympy.core.assumptions import ManagedProperties
class CreateOneQuibitGate(ManagedProperties):
def __new__(mcl, name):
return BasicMeta.__new__(mcl, name + "Gate", (OneQubitGate,),
{'gate_name': name, 'gate_name_latex': name})
Don't worry about the __module__ = None thing from UndefinedFunction;
that's there to make it picklable in certain situations, but it
doesn't really even work. You could probably get away with using
BasicMeta instead of ManagedProperties, but it's probably a bad idea
to use a different metaclass than the rest of the core.
You can of course get more clever with the gate_name and
gate_name_latex. I just used the same name for all, but you might want
to have two or three arguments in the constructor.
It works like this:
In [20]: a = CreateOneQuibitGate('V')
In [21]: a.gate_name
Out[21]: 'V'
In [22]: a()
Out[22]:
V
O
Aaron Meurer