diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-02-02 17:00:32 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-02-02 17:00:32 -0500 |
commit | b517e974e0d3eb4f89c724f9a1e865dc35824c7f (patch) | |
tree | e1dc0f95fbf4d7da679d2922e8c1d62f3bc65872 | |
parent | 11efa216e5ff17fc48b22d27e21194ed7ff8edb1 (diff) | |
download | sqlalchemy-b517e974e0d3eb4f89c724f9a1e865dc35824c7f.tar.gz |
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]
-rw-r--r-- | doc/build/changelog/changelog_07.rst | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/types.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 6 | ||||
-rw-r--r-- | test/sql/test_types.py | 6 |
4 files changed, 22 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_07.rst b/doc/build/changelog/changelog_07.rst index 363e4cbee..c747edb16 100644 --- a/doc/build/changelog/changelog_07.rst +++ b/doc/build/changelog/changelog_07.rst @@ -10,6 +10,14 @@ .. 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 Fixed bug where :meth:`.Table.tometadata` would fail if a diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index f95cecfea..5fe2ba209 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -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. diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 16d564430..b7c5132df 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -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 diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 91bf17175..2995dca79 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -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): |