Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6cc6876

Browse files
authored
feat: add with_name() to ScalarQueryParameterType (#644)
* feat: add with_name() to ScalarQueryParameterType* Clarify unsetting a name, add extra test
1 parentbe3c49a commit6cc6876

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

‎google/cloud/bigquery/query.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
fromcollectionsimportOrderedDict
1818
importcopy
19+
fromtypingimportUnion
1920

2021
fromgoogle.cloud.bigquery.tableimport_parse_schema_resource
2122
fromgoogle.cloud.bigquery._helpersimport_rows_from_json
@@ -119,6 +120,20 @@ def to_api_repr(self):
119120
# attributes in the API representation when needed. Here we omit them.
120121
return {"type":self._type}
121122

123+
defwith_name(self,new_name:Union[str,None]):
124+
"""Return a copy of the instance with ``name`` set to ``new_name``.
125+
126+
Args:
127+
name (Union[str, None]):
128+
The new name of the query parameter type. If ``None``, the existing
129+
name is cleared.
130+
131+
Returns:
132+
google.cloud.bigquery.query.ScalarQueryParameterType:
133+
A new instance with updated name.
134+
"""
135+
returntype(self)(self._type,name=new_name,description=self.description)
136+
122137
def__repr__(self):
123138
name=f", name={self.name!r}"ifself.nameisnotNoneelse""
124139
description= (

‎tests/unit/test_query.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ def test_repr_all_optional_attrs(self):
9898
"ScalarQueryParameterType('BYTES', name='foo', description='this is foo')",
9999
)
100100

101+
deftest_with_name_returns_copy_w_changed_name(self):
102+
param_type=self._make_one("BOOLEAN",name=None,description="Some checkbox.")
103+
modified_type=param_type.with_name("allow_emails")
104+
105+
self.assertIsNot(modified_type,param_type)# Result is a copy.
106+
self.assertEqual(modified_type.name,"allow_emails")
107+
108+
# The rest of the The rest of the fields should have been preserved.
109+
self.assertEqual(modified_type._type,param_type._type)
110+
self.assertEqual(modified_type.description,param_type.description)
111+
112+
deftest_with_name_clearing_the_value(self):
113+
param_type=self._make_one(
114+
"BOOLEAN",name="allow_emails",description="Some checkbox."
115+
)
116+
modified_type=param_type.with_name(None)
117+
118+
self.assertIsNone(modified_type.name)
119+
self.assertEqual(param_type.name,"allow_emails")# original unchanged
120+
101121

102122
classTest_ArrayQueryParameterType(unittest.TestCase):
103123
@staticmethod

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp