Support native Python 3.4 enums with enum type

Issue #3292 resolved
Veeti Paananen created an issue

It would be nice to have built-in integration between the SQLAlchemy enum type and standard Python enums.

Comments (5)

  1. Mike Bayer repo owner

    some discussion at https://bitbucket.org/zzzeek/sqlalchemy/pull-request/51/builtin-enum-recipe/diff.

    My current proposal is to add a minimal integration hook as:

    from any_enum_package import Enum
    class Color(Enum):
        red = 1
        green = 2
        blue = 3
    
    enum_type = sqlalchemy.Enum('red', 'green', 'blue', enum_obj=(Color.red, Color.green, Color.blue))
    

    The Enum type would now deal with "Color.red", "Color.green", and "Color.blue" as the values which are expected as input as well as delivered in output.

  2. Mike Bayer repo owner
    • add changelog and migration notes for new Enum features, fixes #3095, #3292
    • reorganize enum constructor to again work with the MySQL ENUM type
    • add a new create_constraint flag to Enum to complement that of Boolean
    • reinstate the CHECK constraint tests for enum, these already fail /skip against the MySQL backend
    • simplify lookup rules in Enum, have them apply to all varieties of Enum equally

    → <<cset df55695f8e99>>

  3. Log in to comment