Skip to content

Change string format to f-strings #3975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions firestore/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def quickstart_get_collection():
docs = users_ref.stream()

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


Expand Down Expand Up @@ -149,9 +149,14 @@ def to_dict(self):

def __repr__(self):
return(
u'City(name={}, country={}, population={}, capital={}, regions={})'
.format(self.name, self.country, self.population, self.capital,
self.regions))
f'City(\
name={self.name}, \
country={self.country}, \
population={self.population}, \
capital={self.capital}, \
regions={self.regions}\
)'
)
# [END custom_class_def]


Expand Down Expand Up @@ -219,7 +224,7 @@ def get_check_exists():

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

for doc in docs:
print(u'{} => {}'.format(doc.id, doc.to_dict()))
print(f'{doc.id} => {doc.to_dict()}')
# [END get_simple_query]


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


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

for doc in docs:
print(u'{} => {}'.format(doc.id, doc.to_dict()))
print(f'{doc.id} => {doc.to_dict()}')
# [END get_full_collection]


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


def update_multiple():
Expand Down Expand Up @@ -622,7 +627,7 @@ def snapshot_cursors():
# [END fs_start_at_snapshot_query_cursor]
results = start_at_snapshot.limit(10).stream()
for doc in results:
print(u'{}'.format(doc.id))
print(f'{doc.id}')

return results

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

doc_ref = db.collection(u'cities').document(u'SF')
Expand Down Expand Up @@ -705,7 +710,7 @@ def on_snapshot(col_snapshot, changes, read_time):
print(u'Callback received query snapshot.')
print(u'Current cities in California:')
for doc in col_snapshot:
print(u'{}'.format(doc.id))
print(f'{doc.id}')
callback_done.set()

col_query = db.collection(u'cities').where(u'state', u'==', u'CA')
Expand Down Expand Up @@ -741,11 +746,11 @@ def on_snapshot(col_snapshot, changes, read_time):
print(u'Current cities in California: ')
for change in changes:
if change.type.name == 'ADDED':
print(u'New city: {}'.format(change.document.id))
print(f'New city: {change.document.id}')
elif change.type.name == 'MODIFIED':
print(u'Modified city: {}'.format(change.document.id))
print(f'Modified city: {change.document.id}')
elif change.type.name == 'REMOVED':
print(u'Removed city: {}'.format(change.document.id))
print(f'Removed city: {change.document.id}')
delete_done.set()

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

for doc in docs:
print(u'Deleting doc {} => {}'.format(doc.id, doc.to_dict()))
print(f'Deleting doc {doc.id} => {doc.to_dict()}')
doc.reference.delete()
deleted = deleted + 1

Expand Down Expand Up @@ -905,7 +910,7 @@ def collection_group_query(db):
.where(u'type', u'==', u'museum')
docs = museums.stream()
for doc in docs:
print(u'{} => {}'.format(doc.id, doc.to_dict()))
print(f'{doc.id} => {doc.to_dict()}')
# [END fs_collection_group_query]
return docs

Expand Down