From 7f863344b96c945c56791d31b15a302c2ddd800f Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Mon, 23 Mar 2020 21:17:01 +0100 Subject: Improve the method ``__str__`` of :class:`ColumnCollection` The change avoids confusing a :class:`ColumnCollection` with a python list since the previous string representation was the same. Fixes: #5191 Change-Id: Icdbc08f9991d31ce86372505e3614740eaee56e2 --- lib/sqlalchemy/sql/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index 77222706a..f093cad90 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -676,7 +676,7 @@ class ColumnCollection(object): >>> from sqlalchemy import Column, Integer >>> from sqlalchemy.sql import ColumnCollection >>> x, y = Column('x', Integer), Column('y', Integer) - >>> cc = ColumnCollection(columns=[x, y]) + >>> cc = ColumnCollection(columns=[(x.name, x), (y.name, y)]) >>> cc.x Column('x', Integer(), table=None) >>> cc.y @@ -707,7 +707,7 @@ class ColumnCollection(object): returned by key access is **arbitrary**:: >>> x1, x2 = Column('x', Integer), Column('x', Integer) - >>> cc = ColumnCollection(columns=[x1, x2]) + >>> cc = ColumnCollection(columns=[(x1.name, x1), (x2.name, x2)]) >>> list(cc) [Column('x', Integer(), table=None), Column('x', Integer(), table=None)] @@ -808,7 +808,10 @@ class ColumnCollection(object): return default def __str__(self): - return repr([str(c) for c in self]) + return "%s(%s)" % ( + self.__class__.__name__, + ", ".join(str(c) for c in self), + ) def __setitem__(self, key, value): raise NotImplementedError() -- cgit v1.2.1