]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed the repr() of Enum to include
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Aug 2012 23:41:49 +0000 (19:41 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Aug 2012 23:41:49 +0000 (19:41 -0400)
    the "name" and "native_enum" flags.  Helps
    Alembic autogenerate.

CHANGES
lib/sqlalchemy/types.py
lib/sqlalchemy/util/langhelpers.py

diff --git a/CHANGES b/CHANGES
index 068fcede56475b819fff0e8c6105cd7cf1403a96..cd88f62a51ab930827563cfd797662f6314f7b0e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -529,6 +529,10 @@ are also present in 0.8.
     the absense of which was preventing the new
     GAE dialect from being loaded.  [ticket:2529]
 
+  - [bug] Fixed the repr() of Enum to include
+    the "name" and "native_enum" flags.  Helps
+    Alembic autogenerate.
+
 0.7.8
 =====
 - orm
index fe7e4aab570375ec2a1514d2b8b9d7f2336c15fb..658fc77e91a1e321c43dc38fd873d33b5cfd3332 100644 (file)
@@ -1765,7 +1765,7 @@ class Enum(String, SchemaType):
         """
         self.enums = enums
         self.native_enum = kw.pop('native_enum', True)
-        convert_unicode= kw.pop('convert_unicode', None)
+        convert_unicode = kw.pop('convert_unicode', None)
         if convert_unicode is None:
             for e in enums:
                 if isinstance(e, unicode):
@@ -1775,15 +1775,21 @@ class Enum(String, SchemaType):
                 convert_unicode = False
 
         if self.enums:
-            length =max(len(x) for x in self.enums)
+            length = max(len(x) for x in self.enums)
         else:
             length = 0
         String.__init__(self,
-                        length =length,
+                        length=length,
                         convert_unicode=convert_unicode,
                         )
         SchemaType.__init__(self, **kw)
 
+    def __repr__(self):
+        return util.generic_repr(self, [
+                        ("native_enum", True),
+                        ("name", None)
+                    ])
+
     def _should_create_constraint(self, compiler):
         return not self.native_enum or \
                     not compiler.dialect.supports_native_enum
index 83d851f65ad8a9eaa972861206dd68e3e6cf9faf..9258619ec410be600fb1ca81e3b5a505128afccb 100644 (file)
@@ -281,7 +281,7 @@ def unbound_method_to_callable(func_or_cls):
     else:
         return func_or_cls
 
-def generic_repr(obj):
+def generic_repr(obj, additional_kw=()):
     """Produce a __repr__() based on direct association of the __init__()
     specification vs. same-named attributes present.
 
@@ -309,6 +309,15 @@ def generic_repr(obj):
                         yield '%s=%r' % (arg, val)
                 except:
                     pass
+        if additional_kw:
+            for arg, defval in additional_kw:
+                try:
+                    val = getattr(obj, arg, None)
+                    if val != defval:
+                        yield '%s=%r' % (arg, val)
+                except:
+                    pass
+
     return "%s(%s)" % (obj.__class__.__name__, ", ".join(genargs()))
 
 class portable_instancemethod(object):