Skip to content

Commit

Permalink
Upgrade syntax with pyupgrade --py38-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Aug 14, 2024
1 parent 74e0fc6 commit e9003cf
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 21 deletions.
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Requests-OAuthlib documentation build configuration file, created by
# sphinx-quickstart on Fri May 10 11:49:01 2013.
#
Expand Down
1 change: 0 additions & 1 deletion requests_oauthlib/oauth1_auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import logging

from oauthlib.common import extract_params
Expand Down
8 changes: 4 additions & 4 deletions requests_oauthlib/oauth1_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def urldecode(body):

class TokenRequestDenied(ValueError):
def __init__(self, message, response):
super(TokenRequestDenied, self).__init__(message)
super().__init__(message)
self.response = response

@property
Expand All @@ -36,7 +36,7 @@ def status_code(self):

class TokenMissing(ValueError):
def __init__(self, message, response):
super(TokenMissing, self).__init__(message)
super().__init__(message)
self.response = response


Expand Down Expand Up @@ -149,7 +149,7 @@ def __init__(
signature creation.
:param **kwargs: Additional keyword arguments passed to `OAuth1`
"""
super(OAuth1Session, self).__init__()
super().__init__()
self._client = OAuth1(
client_key,
client_secret=client_secret,
Expand Down Expand Up @@ -348,7 +348,7 @@ def _populate_attributes(self, token):
self._client.client.resource_owner_key = token["oauth_token"]
else:
raise TokenMissing(
"Response does not contain a token: {resp}".format(resp=token), token
f"Response does not contain a token: {token}", token
)
if "oauth_token_secret" in token:
self._client.client.resource_owner_secret = token["oauth_token_secret"]
Expand Down
8 changes: 4 additions & 4 deletions requests_oauthlib/oauth2_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class TokenUpdated(Warning):
def __init__(self, token):
super(TokenUpdated, self).__init__()
super().__init__()
self.token = token


Expand Down Expand Up @@ -74,7 +74,7 @@ def __init__(
:param pkce: Set "S256" or "plain" to enable PKCE. Default is disabled.
:param kwargs: Arguments to pass to the Session constructor.
"""
super(OAuth2Session, self).__init__(**kwargs)
super().__init__(**kwargs)
self._client = client or WebApplicationClient(client_id, token=token)
self.token = token or {}
self._scope = scope
Expand All @@ -87,7 +87,7 @@ def __init__(
self._pkce = pkce

if self._pkce not in ["S256", "plain", None]:
raise AttributeError("Wrong value for {}(.., pkce={})".format(self.__class__, self._pkce))
raise AttributeError(f"Wrong value for {self.__class__}(.., pkce={self._pkce})")

# Ensure that requests doesn't do any automatic auth. See #278.
# The default behavior can be re-enabled by setting auth to None.
Expand Down Expand Up @@ -563,7 +563,7 @@ def request(
log.debug("Requesting url %s using method %s.", url, method)
log.debug("Supplying headers %s and data %s", headers, data)
log.debug("Passing through key word arguments %s.", kwargs)
return super(OAuth2Session, self).request(
return super().request(
method, url, headers=headers, data=data, files=files, **kwargs
)

Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import re
Expand All @@ -10,7 +8,7 @@

# Get the version
version_regex = r'__version__ = ["\']([^"\']*)["\']'
with open("requests_oauthlib/__init__.py", "r") as f:
with open("requests_oauthlib/__init__.py") as f:
text = f.read()
match = re.search(version_regex, text)

Expand Down
6 changes: 3 additions & 3 deletions tests/examples/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def tearDown(self):
self.proc.kill()

def replaceVariables(self, filein ,fileout, vars):
with open(filein, "rt") as fin:
with open(fileout, "wt") as fout:
with open(filein) as fin:
with open(fileout, "w") as fout:
for line in fin:
for k, v in vars.items():
line = line.replace(k, v)
Expand All @@ -44,7 +44,7 @@ def run_sample(self, filepath, variables):
:type variables: dict
"""
inpath = os.path.join(cwd, "..", "..", "docs", "examples", filepath)
outpath = os.path.join(cwd, "tmp_{}".format(filepath))
outpath = os.path.join(cwd, f"tmp_{filepath}")
self.replaceVariables(inpath, outpath, variables)

self.proc = subprocess.Popen(
Expand Down
1 change: 0 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import requests
import requests_oauthlib
import oauthlib
Expand Down
6 changes: 3 additions & 3 deletions tests/test_oauth2_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_add_token(self):
token = "Bearer " + self.token["access_token"]

def verifier(r, **kwargs):
auth_header = r.headers.get(str("Authorization"), None)
auth_header = r.headers.get("Authorization", None)
self.assertEqual(auth_header, token)
resp = mock.MagicMock()
resp.cookes = []
Expand Down Expand Up @@ -544,10 +544,10 @@ def setUp(self):
with open(netrc_loc, "w") as f:
f.write("machine i.b\n" " password abc123\n" " login [email protected]\n")

super(OAuth2SessionNetrcTest, self).setUp()
super().setUp()

def tearDown(self):
super(OAuth2SessionNetrcTest, self).tearDown()
super().tearDown()

if self.prehome is not None:
os.environ["HOME"] = self.prehome
Expand Down

0 comments on commit e9003cf

Please sign in to comment.