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:
parent
11efa216e5
commit
b517e974e0
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue