there's a lot of flavors of python enum and I recall the standard library one 
rubs me the wrong way a bit.   I'd prefer for sqlalchemy.Enum to have some easy 
way to accommodate any Python-side enum using some kind of convention, 
obviously one that's compat with the std lib enum.




On Aug 6, 2013, at 5:12 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote:

> Since Python 3.4 is adding support for enums to the standard library,
> I wrote a TypeDecorator for it:
> 
> import sqlalchemy.types as types
> 
> 
> class PythonEnum(types.TypeDecorator):
> 
>    impl = types.Enum
> 
>    def __init__(self, enum_class, **kw):
>        super().__init__(*(m.name for m in enum_class), **kw)
>        self._enum_class = enum_class
> 
>    def process_bind_param(self, value, dialect):
>        return value.name
> 
>    def process_result_value(self, value, dialect):
>        return self._enum_class[value]
> 
>    @property
>    def python_type(self):
>        return self._enum_class
> 
> 
> Comments welcome.  Is this something that should be added to sqlalchemy?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to