diff --git a/social_core/backends/apple.py b/social_core/backends/apple.py index 2325a257f..7339ceb73 100644 --- a/social_core/backends/apple.py +++ b/social_core/backends/apple.py @@ -107,8 +107,7 @@ def get_apple_jwk(self, kid=None): if kid: return json.dumps([key for key in keys if key["kid"] == kid][0]) - else: - return (json.dumps(key) for key in keys) + return (json.dumps(key) for key in keys) def decode_id_token(self, id_token): """ diff --git a/social_core/backends/base.py b/social_core/backends/base.py index 8d3bd2b96..71a1c8bce 100644 --- a/social_core/backends/base.py +++ b/social_core/backends/base.py @@ -32,8 +32,7 @@ def setting(self, name, default=None): def start(self): if self.uses_redirect(): return self.strategy.redirect(self.auth_url()) - else: - return self.strategy.html(self.auth_html()) + return self.strategy.html(self.auth_html()) def complete(self, *args, **kwargs): return self.auth_complete(*args, **kwargs) diff --git a/social_core/backends/google.py b/social_core/backends/google.py index aafc2c761..a050ea2f0 100644 --- a/social_core/backends/google.py +++ b/social_core/backends/google.py @@ -14,10 +14,8 @@ def get_user_id(self, details, response): if self.setting("USE_UNIQUE_USER_ID", False): if "sub" in response: return response["sub"] - else: - return response["id"] - else: - return details["email"] + return response["id"] + return details["email"] def get_user_details(self, response): """Return user details from Google API account""" @@ -115,7 +113,7 @@ def auth_complete(self, *args, **kwargs): ) self.process_error(response) return self.do_auth(token, response=response, *args, **kwargs) - elif "code" in self.data: # Server-side workflow + if "code" in self.data: # Server-side workflow response = self.request_access_token( self.ACCESS_TOKEN_URL, data=self.auth_complete_params(), @@ -126,11 +124,10 @@ def auth_complete(self, *args, **kwargs): return self.do_auth( response["access_token"], response=response, *args, **kwargs ) - elif "id_token" in self.data: # Client-side workflow + if "id_token" in self.data: # Client-side workflow token = self.data.get("id_token") return self.do_auth(token, *args, **kwargs) - else: - raise AuthMissingParameter(self, "access_token, id_token, or code") + raise AuthMissingParameter(self, "access_token, id_token, or code") def user_data(self, access_token, *args, **kwargs): if "id_token" not in self.data: diff --git a/social_core/backends/mediawiki.py b/social_core/backends/mediawiki.py index 5ceb220b7..f6dd1a663 100644 --- a/social_core/backends/mediawiki.py +++ b/social_core/backends/mediawiki.py @@ -21,8 +21,7 @@ def force_unicode(value): """ if isinstance(value, str): return value - else: - return str(value, "unicode-escape") + return str(value, "unicode-escape") class MediaWiki(BaseOAuth1): diff --git a/social_core/backends/open_id.py b/social_core/backends/open_id.py index 064d37e3a..ed694abde 100644 --- a/social_core/backends/open_id.py +++ b/social_core/backends/open_id.py @@ -253,7 +253,6 @@ def openid_url(self): provider URL.""" if self.URL: return self.URL - elif OPENID_ID_FIELD in self.data: + if OPENID_ID_FIELD in self.data: return self.data[OPENID_ID_FIELD] - else: - raise AuthMissingParameter(self, OPENID_ID_FIELD) + raise AuthMissingParameter(self, OPENID_ID_FIELD) diff --git a/social_core/backends/qiita.py b/social_core/backends/qiita.py index dc8d5aa9b..1202a3727 100644 --- a/social_core/backends/qiita.py +++ b/social_core/backends/qiita.py @@ -83,5 +83,4 @@ def get_user_id(self, details, response): if user_id is not None: return str(user_id) - else: - raise AuthException("failed to get user id") + raise AuthException("failed to get user id") diff --git a/social_core/pipeline/social_auth.py b/social_core/pipeline/social_auth.py index 247163371..7ad0d20c8 100644 --- a/social_core/pipeline/social_auth.py +++ b/social_core/pipeline/social_auth.py @@ -74,7 +74,7 @@ def associate_by_email(backend, details, user=None, *args, **kwargs): users = list(backend.strategy.storage.user.get_users_by_email(email)) if len(users) == 0: return None - elif len(users) > 1: + if len(users) > 1: raise AuthException( backend, "The given email address is associated with another account" ) diff --git a/social_core/storage.py b/social_core/storage.py index 392b98003..9e3cb6276 100644 --- a/social_core/storage.py +++ b/social_core/storage.py @@ -74,16 +74,14 @@ def expiration_timedelta(self): # expires is a datetime, return the remaining difference expiry_time = datetime.fromtimestamp(expires, tz=timezone.utc) return expiry_time - now - else: - # expires is the time to live seconds since creation, - # check against auth_time if present, otherwise return - # the value - auth_time = self.extra_data.get("auth_time") - if auth_time: - reference = datetime.fromtimestamp(auth_time, tz=timezone.utc) - return (reference + timedelta(seconds=expires)) - now - else: - return timedelta(seconds=expires) + # expires is the time to live seconds since creation, + # check against auth_time if present, otherwise return + # the value + auth_time = self.extra_data.get("auth_time") + if auth_time: + reference = datetime.fromtimestamp(auth_time, tz=timezone.utc) + return (reference + timedelta(seconds=expires)) - now + return timedelta(seconds=expires) def expiration_datetime(self): # backward compatible alias diff --git a/social_core/store.py b/social_core/store.py index 6dfe9e072..cb6228b8b 100644 --- a/social_core/store.py +++ b/social_core/store.py @@ -30,8 +30,8 @@ def removeAssociation(self, server_url, handle): def expiresIn(self, assoc): if hasattr(assoc, "getExpiresIn"): return assoc.getExpiresIn() - else: # python3-openid 3.0.2 - return assoc.expiresIn + # python3-openid 3.0.2 + return assoc.expiresIn def getAssociation(self, server_url, handle=None): """Return stored association""" diff --git a/social_core/strategy.py b/social_core/strategy.py index 60ab1cd12..604942f1a 100644 --- a/social_core/strategy.py +++ b/social_core/strategy.py @@ -19,8 +19,7 @@ def render(self, tpl=None, html=None, context=None): context = context or {} if tpl: return self.render_template(tpl, context) - else: - return self.render_string(html, context) + return self.render_string(html, context) def render_template(self, tpl, context): raise NotImplementedError("Implement in subclass") @@ -137,13 +136,12 @@ def validate_email(self, email, code): verification_code = self.storage.code.get_code(code) if not verification_code or verification_code.code != code: return False - elif verification_code.email != email: + if verification_code.email != email: return False - elif verification_code.verified: + if verification_code.verified: return False - else: - verification_code.verify() - return True + verification_code.verify() + return True def render_html(self, tpl=None, html=None, context=None): """Render given template or raw html with given context""" diff --git a/social_core/tests/pipeline.py b/social_core/tests/pipeline.py index 7d8d8126a..94a91565f 100644 --- a/social_core/tests/pipeline.py +++ b/social_core/tests/pipeline.py @@ -5,16 +5,14 @@ def ask_for_password(strategy, *args, **kwargs): if strategy.session_get("password"): return {"password": strategy.session_get("password")} - else: - return strategy.redirect(strategy.build_absolute_uri("/password")) + return strategy.redirect(strategy.build_absolute_uri("/password")) @partial def ask_for_slug(strategy, *args, **kwargs): if strategy.session_get("slug"): return {"slug": strategy.session_get("slug")} - else: - return strategy.redirect(strategy.build_absolute_uri("/slug")) + return strategy.redirect(strategy.build_absolute_uri("/slug")) def set_password(strategy, user, *args, **kwargs): diff --git a/social_core/tests/test_pipeline.py b/social_core/tests/test_pipeline.py index 0acd4f0fa..e92ddc50f 100644 --- a/social_core/tests/test_pipeline.py +++ b/social_core/tests/test_pipeline.py @@ -29,8 +29,7 @@ def get_social_auth(cls, provider, uid): if cls._called_times == 2: user = list(User.cache.values())[0] return IntegrityErrorUserSocialAuth(user, provider, uid) - else: - return super().get_social_auth(provider, uid) + return super().get_social_auth(provider, uid) class IntegrityErrorStorage(TestStorage): diff --git a/social_core/utils.py b/social_core/utils.py index b89e0071e..bd47277bb 100644 --- a/social_core/utils.py +++ b/social_core/utils.py @@ -207,8 +207,7 @@ def partial_pipeline_data(backend, user=None, partial_token=None, *args, **kwarg kwargs.setdefault("request", request_data) partial.extend_kwargs(kwargs) return partial - else: - backend.strategy.clean_partial_pipeline(partial_token) + backend.strategy.clean_partial_pipeline(partial_token) def build_absolute_uri(host_url, path=None): @@ -242,10 +241,9 @@ def setting_url(backend, *names): for name in names: if is_url(name): return name - else: - value = backend.setting(name) - if is_url(value): - return value + value = backend.setting(name) + if is_url(value): + return value def handle_http_errors(func):