Skip to content

Commit 4b486f8

Browse files
committed
replace .format() with f strings
1 parent 0fba1a1 commit 4b486f8

File tree

6 files changed

+26
-45
lines changed

6 files changed

+26
-45
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class SpotifyClientCredentials that can be used to authenticate requests like so
145145
playlists = sp.user_playlists('spotify')
146146
while playlists:
147147
for i, playlist in enumerate(playlists['items']):
148-
print("{:4d} {} {}".format(i + 1 + playlists['offset'], playlist['uri'], playlist['name']))
148+
print(f"{i + 1 + playlists['offset']:4d} {playlist['uri']} {playlist['name']}")
149149
if playlists['next']:
150150
playlists = sp.next(playlists)
151151
else:

examples/artist_discography.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def show_artist(artist):
5555
logger.info(f'===={artist["name"]}====')
5656
logger.info(f'Popularity: {artist["popularity"]}')
5757
if len(artist['genres']) > 0:
58-
logger.info('Genres: {}'.format(','.join(artist['genres'])))
58+
logger.info(f"Genres: {', '.join(artist['genres'])}")
5959

6060

6161
def main():

examples/track_recommendations.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,5 @@
3838

3939
# Display the recommendations
4040
for i, track in enumerate(recommendations['tracks']):
41-
print(
42-
"{}. {} by {}"
43-
.format(i+1, track['name'], ', '
44-
.join([artist['name'] for artist in track['artists']]))
45-
)
41+
print(f"{i+1}. {track['name']} by "
42+
f"{', '.join([artist['name'] for artist in track['artists']])}")

spotipy/client.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ def _internal_call(self, method, url, payload, params):
263263
if self.language is not None:
264264
headers["Accept-Language"] = self.language
265265

266-
logger.debug('Sending {} to {} with Params: {} Headers: {} and Body: {!r} '.format(
267-
method, url, args.get("params"), headers, args.get('data')))
266+
logger.debug(f"Sending {method} to {url} with Params: "
267+
f"{args.get('params')} Headers: {headers} and Body: {args.get('data')!r}")
268268

269269
try:
270270
response = self._session.request(
@@ -289,11 +289,8 @@ def _internal_call(self, method, url, payload, params):
289289
msg = response.text or None
290290
reason = None
291291

292-
logger.error(
293-
'HTTP Error for {} to {} with Params: {} returned {} due to {}'.format(
294-
method, url, args.get("params"), response.status_code, msg
295-
)
296-
)
292+
logger.error(f"HTTP Error for {method} to {url} with Params: "
293+
f"{args.get('params')} returned {response.status_code} due to {msg}")
297294

298295
raise SpotifyException(
299296
response.status_code,
@@ -2035,11 +2032,9 @@ def _is_uri(self, uri):
20352032
def _search_multiple_markets(self, q, limit, offset, type, markets, total):
20362033
if total and limit > total:
20372034
limit = total
2038-
warnings.warn(
2039-
"limit was auto-adjusted to equal {} as it must not be higher than total".format(
2040-
total),
2041-
UserWarning,
2042-
)
2035+
warnings.warn(f"limit was auto-adjusted to equal {total} "
2036+
f"as it must not be higher than total",
2037+
UserWarning)
20432038

20442039
results = defaultdict(dict)
20452040
item_types = [item_type + "s" for item_type in type.split(",")]

spotipy/exceptions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ def __init__(self, http_status, code, msg, reason=None, headers=None):
1616
self.headers = headers
1717

1818
def __str__(self):
19-
return 'http status: {}, code:{} - {}, reason: {}'.format(
20-
self.http_status, self.code, self.msg, self.reason)
19+
return (f"http status: {self.http_status}, "
20+
f"code: {self.code} - {self.msg}, "
21+
f"reason: {self.reason}")
2122

2223

2324
class SpotifyOauthError(SpotifyBaseException):

spotipy/oauth2.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ def _request_access_token(self):
217217
self.client_id, self.client_secret
218218
)
219219

220-
logger.debug(
221-
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
222-
self.OAUTH_TOKEN_URL, headers, payload)
223-
)
220+
logger.debug(f"Sending POST request to {self.OAUTH_TOKEN_URL} with Headers: "
221+
f"{headers} and Body: {payload}")
224222

225223
try:
226224
response = self._session.post(
@@ -509,10 +507,8 @@ def get_access_token(self, code=None, as_dict=True, check_cache=True):
509507

510508
headers = self._make_authorization_headers()
511509

512-
logger.debug(
513-
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
514-
self.OAUTH_TOKEN_URL, headers, payload)
515-
)
510+
logger.debug(f"Sending POST request to {self.OAUTH_TOKEN_URL} with Headers: "
511+
f"{headers} and Body: {payload}")
516512

517513
try:
518514
response = self._session.post(
@@ -539,10 +535,8 @@ def refresh_access_token(self, refresh_token):
539535

540536
headers = self._make_authorization_headers()
541537

542-
logger.debug(
543-
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
544-
self.OAUTH_TOKEN_URL, headers, payload)
545-
)
538+
logger.debug(f"Sending POST request to {self.OAUTH_TOKEN_URL} with Headers: "
539+
f"{headers} and Body: {payload}")
546540

547541
try:
548542
response = self._session.post(
@@ -786,10 +780,8 @@ def _get_auth_response_interactive(self, open_browser=False):
786780
prompt = "Enter the URL you were redirected to: "
787781
else:
788782
url = self.get_authorize_url()
789-
prompt = (
790-
"Go to the following URL: {}\n"
791-
"Enter the URL you were redirected to: ".format(url)
792-
)
783+
prompt = (f"Go to the following URL: {url}\n"
784+
f"Enter the URL you were redirected to: ")
793785
response = self._get_user_input(prompt)
794786
state, code = self.parse_auth_response_url(response)
795787
if self.state is not None and self.state != state:
@@ -865,10 +857,8 @@ def get_access_token(self, code=None, check_cache=True):
865857

866858
headers = {"Content-Type": "application/x-www-form-urlencoded"}
867859

868-
logger.debug(
869-
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
870-
self.OAUTH_TOKEN_URL, headers, payload)
871-
)
860+
logger.debug(f"Sending POST request to {self.OAUTH_TOKEN_URL} with Headers: "
861+
f"{headers} and Body: {payload}")
872862

873863
try:
874864
response = self._session.post(
@@ -896,10 +886,8 @@ def refresh_access_token(self, refresh_token):
896886

897887
headers = {"Content-Type": "application/x-www-form-urlencoded"}
898888

899-
logger.debug(
900-
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
901-
self.OAUTH_TOKEN_URL, headers, payload)
902-
)
889+
logger.debug(f"Sending POST request to {self.OAUTH_TOKEN_URL} with Headers: "
890+
f"{headers} and Body: {payload}")
903891

904892
try:
905893
response = self._session.post(

0 commit comments

Comments
 (0)