Skip to content

Commit 3db7ff3

Browse files
committed
Add more informative string repr of SQL type
1 parent adcaa03 commit 3db7ff3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

google/cloud/bigquery/standard_sql.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ def __eq__(self, other):
168168

169169
__hash__ = None
170170

171+
def __str__(self):
172+
result = f"{self.__class__.__name__}(type_kind={self.type_kind!r}, ...)"
173+
return result
174+
171175

172176
class StandardSqlField:
173177
"""A field or a column.

tests/unit/test_standard_sql_types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ def test_from_api_repr_struct_type_incomplete_field_info(self):
275275
)
276276
assert result == expected
277277

278+
def test_str(self):
279+
instance = self._make_one(type_kind=bigquery.StandardSqlTypeNames.BOOL)
280+
bool_type_repr = repr(bigquery.StandardSqlTypeNames.BOOL)
281+
assert str(instance) == f"StandardSqlDataType(type_kind={bool_type_repr}, ...)"
282+
278283

279284
class TestStandardSqlTableType:
280285
@staticmethod

0 commit comments

Comments
 (0)