From: Mike Bayer Date: Wed, 8 Aug 2012 23:41:49 +0000 (-0400) Subject: - [bug] Fixed the repr() of Enum to include X-Git-Tag: rel_0_8_0b1~276 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a087179ba9e588b3383f0861f389f9437ff1b979;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [bug] Fixed the repr() of Enum to include the "name" and "native_enum" flags. Helps Alembic autogenerate. --- diff --git a/CHANGES b/CHANGES index 068fcede56..cd88f62a51 100644 --- 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 diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index fe7e4aab57..658fc77e91 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -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 diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 83d851f65a..9258619ec4 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -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):