Skip to content

Commit 6e063e0

Browse files
authored
feat: upgrade sample style (Cloud SDK) (GoogleCloudPlatform#9942)
* feat: upgrade sample style (Cloud SDK) * copyright headers
1 parent 2a633ee commit 6e063e0

File tree

19 files changed

+290
-298
lines changed

19 files changed

+290
-298
lines changed

cloud-sql/postgres/sqlalchemy/connect_unix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def connect_unix_socket() -> sqlalchemy.engine.base.Engine:
4040
username=db_user,
4141
password=db_pass,
4242
database=db_name,
43-
query={"unix_sock": "{}/.s.PGSQL.5432".format(unix_socket_path)},
43+
query={"unix_sock": f"{unix_socket_path}/.s.PGSQL.5432"},
4444
),
4545
# [START_EXCLUDE]
4646
# Pool size is the maximum number of permanent connections to keep.

cloud_tasks/snippets/create_http_task.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from __future__ import print_function
18-
1917
import argparse
2018

2119

@@ -98,7 +96,7 @@ def create_http_task(
9896
# Use the client to build and send the task.
9997
response = client.create_task(request={"parent": parent, "task": task})
10098

101-
print("Created task {}".format(response.name))
99+
print(f"Created task {response.name}")
102100
# [END cloud_tasks_create_http_task]
103101
return response
104102

cloud_tasks/snippets/create_http_task_with_token.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from __future__ import print_function
18-
1917

2018
def create_http_task(
2119
project,
@@ -68,7 +66,7 @@ def create_http_task(
6866
# Use the client to build and send the task.
6967
response = client.create_task(request={"parent": parent, "task": task})
7068

71-
print("Created task {}".format(response.name))
69+
print(f"Created task {response.name}")
7270
return response
7371

7472

cloud_tasks/snippets/create_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create_queue(project, queue_name, location):
3030
# Use the client to create the queue.
3131
response = client.create_queue(request={"parent": parent, "queue": queue})
3232

33-
print("Created queue {}".format(response.name))
33+
print(f"Created queue {response.name}")
3434
return response
3535

3636

datastore/cloud-client/snippets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,6 @@ def eventual_consistent_query(client):
904904
query = client.query(kind="Task")
905905
query.fetch(eventual=True)
906906
# [END datastore_eventual_consistent_query]
907-
pass
908907

909908

910909
def index_merge_queries(client):

datastore/cloud-client/snippets_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333

3434
class CleanupClient(datastore.Client):
3535
def __init__(self, *args, **kwargs):
36-
super(CleanupClient, self).__init__(*args, **kwargs)
36+
super().__init__(*args, **kwargs)
3737
self.entities_to_delete = []
3838
self.keys_to_delete = []
3939

4040
def cleanup(self):
4141
batch = self.batch()
4242
batch.begin()
4343
self.delete_multi(
44-
list(set([x.key for x in self.entities_to_delete if x]))
44+
list({x.key for x in self.entities_to_delete if x})
4545
+ list(set(self.keys_to_delete))
4646
)
4747
batch.commit(retry=retry_policy)

firestore/cloud-async-client/distributed_counters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from google.cloud import firestore
1919

2020

21-
class Shard(object):
21+
class Shard:
2222
"""
2323
A shard is a distributed counter. Each shard can support being incremented
2424
once per second. Multiple shards are needed within a Counter to allow
@@ -32,7 +32,7 @@ def to_dict(self):
3232
return {"count": self._count}
3333

3434

35-
class Counter(object):
35+
class Counter:
3636
"""
3737
A counter stores a collection of shards which are
3838
summed to return a total count. This allows for more

firestore/cloud-async-client/snippets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def add_data_types():
8686

8787

8888
# [START firestore_data_custom_type_definition_async]
89-
class City(object):
89+
class City:
9090
def __init__(self, name, state, country, capital=False, population=0, regions=[]):
9191
self.name = name
9292
self.state = state

firestore/cloud-async-client/snippets_test.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Copyright 2020, Google, Inc.
1+
# Copyright 2020 Google, Inc.
2+
#
23
# Licensed under the Apache License, Version 2.0 (the "License");
34
# you may not use this file except in compliance with the License.
45
# You may obtain a copy of the License at
56
#
6-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
78
#
89
# Unless required by applicable law or agreed to in writing, software
910
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -27,11 +28,11 @@
2728
class TestFirestoreAsyncClient(firestore.AsyncClient):
2829
def __init__(self, *args, **kwargs):
2930
self._UNIQUE_STRING = UNIQUE_STRING
30-
self._super = super(TestFirestoreAsyncClient, self)
31+
self._super = super()
3132
self._super.__init__(*args, **kwargs)
3233

3334
def collection(self, collection_name, *args, **kwargs):
34-
collection_name += "-{}".format(self._UNIQUE_STRING)
35+
collection_name += f"-{self._UNIQUE_STRING}"
3536
return self._super.collection(collection_name, *args, **kwargs)
3637

3738

@@ -172,7 +173,7 @@ async def test_update_multiple():
172173

173174

174175
async def test_update_server_timestamp(db):
175-
await db.collection(u"objects").document(u"some-id").set({"timestamp": 0})
176+
await db.collection("objects").document("some-id").set({"timestamp": 0})
176177
await snippets.update_server_timestamp()
177178

178179

@@ -294,13 +295,13 @@ async def test_delete_full_collection():
294295
# TODO: b/132092178
295296
async def test_collection_group_query(db):
296297
museum_docs = await snippets.collection_group_query(db)
297-
names = set([museum.name for museum in museum_docs])
298+
names = {museum.name for museum in museum_docs}
298299
assert names == {
299-
u"Legion of Honor",
300-
u"The Getty",
301-
u"National Air and Space Museum",
302-
u"National Museum of Nature and Science",
303-
u"Beijing Ancient Observatory",
300+
"Legion of Honor",
301+
"The Getty",
302+
"National Air and Space Museum",
303+
"National Museum of Nature and Science",
304+
"Beijing Ancient Observatory",
304305
}
305306

306307

firestore/cloud-client/distributed_counters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from google.cloud import firestore
1919

2020

21-
class Shard(object):
21+
class Shard:
2222
"""
2323
A shard is a distributed counter. Each shard can support being incremented
2424
once per second. Multiple shards are needed within a Counter to allow
@@ -32,7 +32,7 @@ def to_dict(self):
3232
return {"count": self._count}
3333

3434

35-
class Counter(object):
35+
class Counter:
3636
"""
3737
A counter stores a collection of shards which are
3838
summed to return a total count. This allows for more

0 commit comments

Comments
 (0)