Skip to content

Commit 2d6afd5

Browse files
sdlinbusunkim96
andauthored
Change str format to f-strings. (#3975)
Co-authored-by: Bu Sun Kim <[email protected]>
1 parent 86080b8 commit 2d6afd5

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

firestore/cloud-client/snippets.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def quickstart_get_collection():
6161
docs = users_ref.stream()
6262

6363
for doc in docs:
64-
print(u'{} => {}'.format(doc.id, doc.to_dict()))
64+
print(f'{doc.id} => {doc.to_dict()}')
6565
# [END quickstart_get_collection]
6666

6767

@@ -149,9 +149,14 @@ def to_dict(self):
149149

150150
def __repr__(self):
151151
return(
152-
u'City(name={}, country={}, population={}, capital={}, regions={})'
153-
.format(self.name, self.country, self.population, self.capital,
154-
self.regions))
152+
f'City(\
153+
name={self.name}, \
154+
country={self.country}, \
155+
population={self.population}, \
156+
capital={self.capital}, \
157+
regions={self.regions}\
158+
)'
159+
)
155160
# [END custom_class_def]
156161

157162

@@ -219,7 +224,7 @@ def get_check_exists():
219224

220225
doc = doc_ref.get()
221226
if doc.exists:
222-
print(u'Document data: {}'.format(doc.to_dict()))
227+
print(f'Document data: {doc.to_dict()}')
223228
else:
224229
print(u'No such document!')
225230
# [END get_check_exists]
@@ -242,7 +247,7 @@ def get_simple_query():
242247
docs = db.collection(u'cities').where(u'capital', u'==', True).stream()
243248

244249
for doc in docs:
245-
print(u'{} => {}'.format(doc.id, doc.to_dict()))
250+
print(f'{doc.id} => {doc.to_dict()}')
246251
# [END get_simple_query]
247252

248253

@@ -255,7 +260,7 @@ def array_contains_filter():
255260
# [END fs_array_contains_filter]
256261
docs = query.stream()
257262
for doc in docs:
258-
print(u'{} => {}'.format(doc.id, doc.to_dict()))
263+
print(f'{doc.id} => {doc.to_dict()}')
259264

260265

261266
def get_full_collection():
@@ -264,7 +269,7 @@ def get_full_collection():
264269
docs = db.collection(u'cities').stream()
265270

266271
for doc in docs:
267-
print(u'{} => {}'.format(doc.id, doc.to_dict()))
272+
print(f'{doc.id} => {doc.to_dict()}')
268273
# [END get_full_collection]
269274

270275

@@ -332,7 +337,7 @@ def update_doc_array():
332337
city_ref.update({u'regions': firestore.ArrayRemove([u'east_coast'])})
333338
# [END fs_update_doc_array]
334339
city = city_ref.get()
335-
print(u'Updated the regions field of the DC. {}'.format(city.to_dict()))
340+
print(f'Updated the regions field of the DC. {city.to_dict()}')
336341

337342

338343
def update_multiple():
@@ -622,7 +627,7 @@ def snapshot_cursors():
622627
# [END fs_start_at_snapshot_query_cursor]
623628
results = start_at_snapshot.limit(10).stream()
624629
for doc in results:
625-
print(u'{}'.format(doc.id))
630+
print(f'{doc.id}')
626631

627632
return results
628633

@@ -667,7 +672,7 @@ def listen_document():
667672
# Create a callback on_snapshot function to capture changes
668673
def on_snapshot(doc_snapshot, changes, read_time):
669674
for doc in doc_snapshot:
670-
print(u'Received document snapshot: {}'.format(doc.id))
675+
print(f'Received document snapshot: {doc.id}')
671676
callback_done.set()
672677

673678
doc_ref = db.collection(u'cities').document(u'SF')
@@ -705,7 +710,7 @@ def on_snapshot(col_snapshot, changes, read_time):
705710
print(u'Callback received query snapshot.')
706711
print(u'Current cities in California:')
707712
for doc in col_snapshot:
708-
print(u'{}'.format(doc.id))
713+
print(f'{doc.id}')
709714
callback_done.set()
710715

711716
col_query = db.collection(u'cities').where(u'state', u'==', u'CA')
@@ -741,11 +746,11 @@ def on_snapshot(col_snapshot, changes, read_time):
741746
print(u'Current cities in California: ')
742747
for change in changes:
743748
if change.type.name == 'ADDED':
744-
print(u'New city: {}'.format(change.document.id))
749+
print(f'New city: {change.document.id}')
745750
elif change.type.name == 'MODIFIED':
746-
print(u'Modified city: {}'.format(change.document.id))
751+
print(f'Modified city: {change.document.id}')
747752
elif change.type.name == 'REMOVED':
748-
print(u'Removed city: {}'.format(change.document.id))
753+
print(f'Removed city: {change.document.id}')
749754
delete_done.set()
750755

751756
col_query = db.collection(u'cities').where(u'state', u'==', u'CA')
@@ -835,7 +840,7 @@ def delete_collection(coll_ref, batch_size):
835840
deleted = 0
836841

837842
for doc in docs:
838-
print(u'Deleting doc {} => {}'.format(doc.id, doc.to_dict()))
843+
print(f'Deleting doc {doc.id} => {doc.to_dict()}')
839844
doc.reference.delete()
840845
deleted = deleted + 1
841846

@@ -905,7 +910,7 @@ def collection_group_query(db):
905910
.where(u'type', u'==', u'museum')
906911
docs = museums.stream()
907912
for doc in docs:
908-
print(u'{} => {}'.format(doc.id, doc.to_dict()))
913+
print(f'{doc.id} => {doc.to_dict()}')
909914
# [END fs_collection_group_query]
910915
return docs
911916

0 commit comments

Comments
 (0)