]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Backported adjustment to ``__repr__`` for
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 2 Feb 2013 22:00:32 +0000 (17:00 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 2 Feb 2013 22:00:32 +0000 (17:00 -0500)
:class:`.TypeDecorator` to 0.7, allows :class:`.PickleType`
to produce a clean ``repr()`` to help with Alembic.
[ticket:2594] [ticket:2584]

doc/build/changelog/changelog_07.rst
lib/sqlalchemy/types.py
lib/sqlalchemy/util/langhelpers.py
test/sql/test_types.py

index 363e4cbee8dd1f49f96bcefc3d3e176e96a518db..c747edb169d07ab1d605cd7bb9c6c01c00490f89 100644 (file)
@@ -8,6 +8,14 @@
     :version: 0.7.10
     :released:
 
+    .. change::
+        :tags: sql, bug
+        :tickets: 2594, 2584
+
+        Backported adjustment to ``__repr__`` for
+        :class:`.TypeDecorator` to 0.7, allows :class:`.PickleType`
+        to produce a clean ``repr()`` to help with Alembic.
+
     .. change::
         :tags: sql, bug
         :tickets: 2643
index f95cecfea020d35509c7376cbf4e3eced3f6218d..5fe2ba209eb2e6170114b32f58d022470197ac91 100644 (file)
@@ -777,6 +777,9 @@ class TypeDecorator(TypeEngine):
         else:
             return op, typ
 
+    def __repr__(self):
+        return util.generic_repr(self, to_inspect=self.impl)
+
 class Variant(TypeDecorator):
     """A wrapping type that selects among a variety of
     implementations based on dialect in use.
@@ -936,6 +939,7 @@ def adapt_type(typeobj, colspecs):
 
 
 
+
 class NullType(TypeEngine):
     """An unknown type.
 
index 16d56443090fdd6e6a41e028b2dffb9d24169625..b7c5132df856c21ff53c1bf63c002f50c2b7aad4 100644 (file)
@@ -239,14 +239,16 @@ def unbound_method_to_callable(func_or_cls):
     else:
         return func_or_cls
 
-def generic_repr(obj, additional_kw=()):
+def generic_repr(obj, additional_kw=(), to_inspect=None):
     """Produce a __repr__() based on direct association of the __init__()
     specification vs. same-named attributes present.
 
     """
+    if to_inspect is None:
+        to_inspect = obj
     def genargs():
         try:
-            (args, vargs, vkw, defaults) = inspect.getargspec(obj.__init__)
+            (args, vargs, vkw, defaults) = inspect.getargspec(to_inspect.__init__)
         except TypeError:
             return
 
index 91bf17175f0219fc656c8fce9ce84ce570dae0e8..2995dca79f45328fbac1cb4b088607222446b509 100644 (file)
@@ -335,6 +335,12 @@ class UserDefinedTest(fixtures.TablesTest, AssertsCompiledSQL):
                 Float().dialect_impl(pg).__class__
         )
 
+    def test_type_decorator_repr(self):
+        class MyType(TypeDecorator):
+            impl = VARCHAR
+
+        eq_(repr(MyType(45)), "MyType(length=45)")
+
     def test_user_defined_typedec_impl_bind(self):
         class TypeOne(types.TypeEngine):
             def bind_processor(self, dialect):