Yes by providing a metaclass . This is a bad idea because metaclasses do not compose very well, and it is magical and confusing.
>>> class A(type): ... def __repr__(self): ... return '<this is not a class!>' ... >>> class B(object): ... __metaclass__ = A ... >>> print B <this is not a class!>
(you can also change __str__ , it depends on the semantics of what it is)
You updated the message to talk about generating SQL queries from the class. Instead of changing str(Class) , why not use Class.__name__ (i.e. the Name that you defined) instead, or perhaps Class.table_name (i.e. Any attribute of the class that you define for each class)? The ability to go through classes and automate their work, since the names of tables that do not belong to the <class 'foo.x'> form are potentially very confusing for future readers of your code, because it is not clear that this should work out of context. The reader must remember that metaclassical hacks were involved (a relatively rare thing, although not in ORM!) And what the metaclass did. On the contrary, just passing Class.table_name instead of Class makes it very obvious what is happening.
Devin jeanpierre
source share