It makes sense to subclass the type directly if I'm not messing with
result or bind values. This works:

class StringEnum(types.Enum):
    def __init__(self, *args, **kwargs):
        super(StringEnum, self).__init__(*args, native_enum=False,
**kwargs)
        self.length = 255

I'm still curious why the TypeDecorator I pasted previously doesn't
work though. The superconstructor does the self.impl =
self.__class__.impl(...) anyway so I figured this was the better
approach than calling self.impl = Enum(...).

On Aug 9, 2:56 pm, Michael Bayer <[email protected]> wrote:
> TypeDecorator doesn't affect the decorated type via subclassing, it affects 
> it via the "impl" attribute, hence "decorates".   So you say self.impl = 
> Enum(...).      You don't need to use TypeDecorator here if all you want to 
> do is create an Enum with default arguments, just subclass Enum directly.
>
> On Aug 9, 2010, at 8:24 AM, Nikolaj wrote:
>
> > I'm on MySQL and trying to create a type that stores enums as
> > VARCHAR(255). However, the following code still issues an ENUM() DDL.
> > What am I doing wrong here?
>
> > class StringEnum(types.TypeDecorator):
> >    impl = types.Enum
>
> >    def __init__(self, *args, **kwargs):
> >        super(StringEnum, self).__init__(*args, native_enum=False,
> > **kwargs)
> >        self.length = 255
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "sqlalchemy" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/sqlalchemy?hl=en.

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

Reply via email to