summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/base.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-03-23 21:17:01 +0100
committerFederico Caselli <cfederico87@gmail.com>2020-03-24 19:59:52 +0100
commit7f863344b96c945c56791d31b15a302c2ddd800f (patch)
tree6b83862084b22ccdf1436c60c5d3e82caeb80821 /lib/sqlalchemy/sql/base.py
parente6b6ec78e6d6f96537eaf542f469a7e88134e9fc (diff)
downloadsqlalchemy-7f863344b96c945c56791d31b15a302c2ddd800f.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy/sql/base.py')
-rw-r--r--lib/sqlalchemy/sql/base.py9
1 files changed, 6 insertions, 3 deletions
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()