Backported adjustment to ``__repr__`` for

:class:`.TypeDecorator` to 0.7, allows :class:`.PickleType`
to produce a clean ``repr()`` to help with Alembic.
[ticket:2594] [ticket:2584]
This commit is contained in:
Mike Bayer 2013-02-02 17:00:32 -05:00
parent 11efa216e5
commit b517e974e0
4 changed files with 22 additions and 2 deletions

View 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

View 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.

View 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

View 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):