Skip to content

Commit 54102e9

Browse files
committed
chore: use f-strings where applicable
1 parent 74e2020 commit 54102e9

17 files changed

+23
-24
lines changed

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ ignore = [
9494
"PERF203", # WONTFIX: This rule is only enforced for Python versions prior to 3.11
9595
"ISC003", # TODO: Explicitly concatenated string should be implicitly concatenated
9696
"B028", # TODO: No explicit `stacklevel` keyword argument found
97-
"UP031", # TODO: Use format specifiers instead of percent format
9897
"PLW0603", # TODO: Using the global statement to update `BACKENDSCACHE` is discouraged
9998
"TRY301", # TODO: Abstract `raise` to an inner function
10099
"BLE001", # TODO: Do not catch blind exception: `Exception`

social_core/backends/classlink.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_user_details(self, response):
3737
def user_data(self, token, *args, **kwargs):
3838
"""Loads user data from service"""
3939
url = "https://nodeapi.classlink.com/v2/my/info"
40-
auth_header = {"Authorization": "Bearer %s" % token}
40+
auth_header = {"Authorization": f"Bearer {token}"}
4141
try:
4242
return self.get_json(url, headers=auth_header)
4343
except ValueError:

social_core/backends/clever.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def user_data(self, token, *args, **kwargs):
5050
"""Loads user data from service"""
5151
identity_url = "https://api.clever.com/v3.0/me"
5252
user_details_url = "https://api.clever.com/v3.0/users"
53-
auth_header = {"Authorization": "Bearer %s" % token}
53+
auth_header = {"Authorization": f"Bearer {token}"}
5454
try:
5555
response = self.get_json(identity_url, headers=auth_header)
5656
user_id = response.get("data", {}).get("id")
57-
user_details_url = "https://api.clever.com/v3.0/users/%s" % user_id
57+
user_details_url = f"https://api.clever.com/v3.0/users/{user_id}"
5858
return self.get_json(user_details_url, headers=auth_header)
5959
except ValueError:
6060
return None

social_core/backends/digitalocean.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_user_details(self, response):
3636
def user_data(self, token, *args, **kwargs):
3737
"""Loads user data from service"""
3838
url = "https://api.digitalocean.com/v2/account"
39-
auth_header = {"Authorization": "Bearer %s" % token}
39+
auth_header = {"Authorization": f"Bearer {token}"}
4040
try:
4141
return self.get_json(url, headers=auth_header)
4242
except ValueError:

social_core/backends/discord.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
class DiscordOAuth2(BaseOAuth2):
1010
name = "discord"
1111
HOSTNAME = "discord.com"
12-
AUTHORIZATION_URL = "https://%s/api/oauth2/authorize" % HOSTNAME
13-
ACCESS_TOKEN_URL = "https://%s/api/oauth2/token" % HOSTNAME
12+
AUTHORIZATION_URL = f"https://{HOSTNAME}/api/oauth2/authorize"
13+
ACCESS_TOKEN_URL = f"https://{HOSTNAME}/api/oauth2/token"
1414
ACCESS_TOKEN_METHOD = "POST"
15-
REVOKE_TOKEN_URL = "https://%s/api/oauth2/token/revoke" % HOSTNAME
15+
REVOKE_TOKEN_URL = f"https://{HOSTNAME}/api/oauth2/token/revoke"
1616
REVOKE_TOKEN_METHOD = "GET"
1717
DEFAULT_SCOPE = ["identify"]
1818
SCOPE_SEPARATOR = "+"
@@ -26,6 +26,6 @@ def get_user_details(self, response):
2626
}
2727

2828
def user_data(self, access_token, *args, **kwargs):
29-
url = "https://%s/api/users/@me" % self.HOSTNAME
30-
auth_header = {"Authorization": "Bearer %s" % access_token}
29+
url = f"https://{self.HOSTNAME}/api/users/@me"
30+
auth_header = {"Authorization": f"Bearer {access_token}"}
3131
return self.get_json(url, headers=auth_header)

social_core/backends/docker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ def user_data(self, access_token, *args, **kwargs):
4242
"""Grab user profile information from Docker Hub."""
4343
username = kwargs["response"]["username"]
4444
return self.get_json(
45-
"https://hub.docker.com/api/v1.1/users/%s/" % username,
46-
headers={"Authorization": "Bearer %s" % access_token},
45+
f"https://hub.docker.com/api/v1.1/users/{username}/",
46+
headers={"Authorization": f"Bearer {access_token}"},
4747
)

social_core/backends/drip.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ def get_user_details(self, response):
2525
def user_data(self, access_token, *args, **kwargs):
2626
return self.get_json(
2727
"https://api.getdrip.com/v2/user",
28-
headers={"Authorization": "Bearer %s" % access_token},
28+
headers={"Authorization": f"Bearer {access_token}"},
2929
)

social_core/backends/fitbit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_user_details(self, response):
5454

5555
def user_data(self, access_token, *args, **kwargs):
5656
"""Loads user data from service"""
57-
auth_header = {"Authorization": "Bearer %s" % access_token}
57+
auth_header = {"Authorization": f"Bearer {access_token}"}
5858
return self.get_json(
5959
"https://api.fitbit.com/1/user/-/profile.json", headers=auth_header
6060
)["user"]

social_core/backends/google.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def user_data(self, access_token, *args, **kwargs):
4545
return self.get_json(
4646
"https://www.googleapis.com/oauth2/v3/userinfo",
4747
headers={
48-
"Authorization": "Bearer %s" % access_token,
48+
"Authorization": f"Bearer {access_token}",
4949
},
5050
)
5151

social_core/backends/mineid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def user_data(self, access_token, *args, **kwargs):
1919
return self._user_data(access_token)
2020

2121
def _user_data(self, access_token, path=None):
22-
url = "%(scheme)s://%(host)s/api/user" % self.get_mineid_url_params()
22+
url = "{scheme}://{host}/api/user".format(**self.get_mineid_url_params())
2323
return self.get_json(url, params={"access_token": access_token})
2424

2525
@property

social_core/backends/paypal.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PayPalOAuth2(BaseOAuth2):
2222
REDIRECT_STATE = False
2323

2424
def user_data(self, access_token, *args, **kwargs):
25-
auth_header = {"Authorization": "Bearer %s" % access_token}
25+
auth_header = {"Authorization": f"Bearer {access_token}"}
2626
return self.get_json(self.USER_DATA_URL, headers=auth_header)
2727

2828
def get_user_details(self, response):
@@ -49,7 +49,7 @@ def auth_complete_params(self, state=None):
4949
}
5050

5151
def auth_headers(self):
52-
auth = ("%s:%s" % self.get_key_and_secret()).encode()
52+
auth = ("{}:{}".format(*self.get_key_and_secret())).encode()
5353
return {"Authorization": b"Basic " + base64.urlsafe_b64encode(auth)}
5454

5555
def refresh_token_params(self, token, *args, **kwargs):

social_core/backends/pocket.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def auth_url(self):
3333
token = self.get_json(self.REQUEST_TOKEN_URL, data=data)["code"]
3434
self.strategy.session_set("pocket_request_token", token)
3535
bits = (self.AUTHORIZATION_URL, token, self.redirect_uri)
36-
return "%s?request_token=%s&redirect_uri=%s" % bits
36+
return "{}?request_token={}&redirect_uri={}".format(*bits)
3737

3838
@handle_http_errors
3939
def auth_complete(self, *args, **kwargs):

social_core/backends/podio.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_user_details(self, response):
2828
response["profile"]["name"]
2929
)
3030
return {
31-
"username": "user_%d" % response["user"]["user_id"],
31+
"username": f"user_{response['user']['user_id']}",
3232
"email": response["user"]["mail"],
3333
"fullname": fullname,
3434
"first_name": first_name,

social_core/backends/shimmering.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_user_details(self, response):
3131

3232
def user_data(self, access_token, *args, **kwargs):
3333
"""Loads user data from service"""
34-
headers = {"Authorization": "Bearer %s" % access_token}
34+
headers = {"Authorization": f"Bearer {access_token}"}
3535
return self.get_json(
3636
"http://developers.shimmeringverify.com/user_info/", headers=headers
3737
)

social_core/backends/slack.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def user_data(self, access_token, *args, **kwargs):
5151
"""Loads user data from service"""
5252
response = self.get_json(
5353
"https://slack.com/api/users.identity",
54-
headers={"Authorization": "Bearer %s" % access_token},
54+
headers={"Authorization": f"Bearer {access_token}"},
5555
)
5656
if not response.get("id", None):
5757
response["id"] = response["user"]["id"]

social_core/backends/twitch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_user_details(self, response):
6363
def user_data(self, access_token, *args, **kwargs):
6464
client_id, _ = self.get_key_and_secret()
6565
auth_headers = {
66-
"Authorization": "Bearer %s" % access_token,
66+
"Authorization": f"Bearer {access_token}",
6767
"Client-Id": client_id,
6868
}
6969
url = "https://api.twitch.tv/helix/users"

social_core/backends/twitter_oauth2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ def user_data(self, access_token, *args, **kwargs):
9999
response = self.get_json(
100100
"https://api.twitter.com/2/users/me",
101101
params={"user.fields": ",".join(fields)},
102-
headers={"Authorization": "Bearer %s" % access_token},
102+
headers={"Authorization": f"Bearer {access_token}"},
103103
)
104104
return response["data"]

0 commit comments

Comments
 (0)