[sqlalchemy] @compiles ignores inheritance

2010-03-30 Thread Tobias
Hi,

I am having a bunch of classes that inherit from Function and all of
them should be compiled by a method annotated with @compiles.


class __base_function(Function):
def __init__(self, clause, *clauses, **kw):
self.clause = clause

Function.__init__(self, self.__class__.__name__, *clauses,
**kw)

class wkt(__base_function):
pass

class wkb(__base_function):
pass

[..]

So I thought I could write just one method, that is annotated with
@compiles(__base_function), but this does not work. I have to write a
method for each class that inherits from __base_function:

@compiles(wkt)
def compile_wkt(element, compiler, **kw):
return __call_function(element, compiler)

@compiles(wkb)
def compile_wkb(element, compiler, **kw):
return __call_function(element, compiler)

[..]

Is there a more elegant way that I do not have to write a method for
each class?

Thank you,
Tobias

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] @compiles ignores inheritance

2010-03-30 Thread Michael Bayer
Tobias wrote:
 Hi,


 So I thought I could write just one method, that is annotated with
 @compiles(__base_function), but this does not work. I have to write a
 method for each class that inherits from __base_function:

 @compiles(wkt)
 def compile_wkt(element, compiler, **kw):
 return __call_function(element, compiler)

 @compiles(wkb)
 def compile_wkb(element, compiler, **kw):
 return __call_function(element, compiler)


none of that was really working (including, can't even have @compiles on
the base and subclass at the same time) so that all works in
rea184f5ba747.   latest tip.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.