Skip to content

Commit 6c9a18d

Browse files
authored
fix: simplify UnsupportedTypeError message (#2212)
* fix: simplify UnsupportedTypeError message * relax assertion
1 parent 2e2f119 commit 6c9a18d

3 files changed

Lines changed: 66 additions & 2 deletions

File tree

‎bigframes/functions/function_typing.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,22 @@ class UnsupportedTypeError(ValueError):
6060
def__init__(self, type_, supported_types):
6161
self.type=type_
6262
self.supported_types=supported_types
63+
64+
types_to_format=supported_types
65+
ifisinstance(supported_types, dict):
66+
types_to_format=supported_types.keys()
67+
68+
supported_types_str=", ".join(
69+
sorted(
70+
[
71+
getattr(supported, "__name__", supported)
72+
forsupportedintypes_to_format
73+
]
74+
)
75+
)
76+
6377
super().__init__(
64-
f"'{type_}' must be one of the supported types ({supported_types}) "
78+
f"'{getattr(type_, '__name__', type_)}' must be one of the supported types ({supported_types_str}) "
6579
"or a list of one of those types."
6680
)
6781

‎tests/system/small/functions/test_remote_function.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ def func_tuple(x):
16461646

16471647
withpytest.raises(
16481648
ValueError,
1649-
match=r"'typing\.Sequence\[int\]' must be one of the supported types",
1649+
match=r"must be one of the supported types",
16501650
):
16511651
bff.remote_function(
16521652
input_types=int,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
importdatetime
16+
importdecimal
17+
18+
importpytest
19+
20+
frombigframes.functionsimportfunction_typing
21+
22+
23+
deftest_unsupported_type_error_init_with_dict():
24+
err=function_typing.UnsupportedTypeError(
25+
decimal.Decimal, {int: "INT64", float: "FLOAT64"}
26+
)
27+
28+
message=str(err)
29+
30+
assert"Decimal"inmessage
31+
assert"float, int"inmessage
32+
33+
34+
deftest_unsupported_type_error_init_with_set():
35+
err=function_typing.UnsupportedTypeError(decimal.Decimal, {int, float})
36+
37+
message=str(err)
38+
39+
assert"Decimal"inmessage
40+
assert"float, int"inmessage
41+
42+
43+
deftest_sdk_type_from_python_type_raises_unsupported_type_error():
44+
withpytest.raises(function_typing.UnsupportedTypeError) asexcinfo:
45+
function_typing.sdk_type_from_python_type(datetime.datetime)
46+
47+
message=str(excinfo.value)
48+
49+
assert"datetime"inmessage
50+
assert"bool, bytes, float, int, str"inmessage

0 commit comments

Comments
 (0)