Skip to content

Commit

Permalink
Simplify Python code with ruff --select=SIM --fix . (#769)
Browse files Browse the repository at this point in the history
* Simplify Python code with ruff --select=SIM --fix .
  • Loading branch information
cclauss committed Feb 27, 2023
1 parent 3e85431 commit e35d81e
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 25 deletions.
5 changes: 1 addition & 4 deletions social_core/backends/clef.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ def get_user_details(self, response):
)

email = info.get("email", "")
if email:
username = email.split("@", 1)[0]
else:
username = info.get("id")
username = email.split("@", 1)[0] if email else info.get("id")

return {
"username": username,
Expand Down
5 changes: 1 addition & 4 deletions social_core/backends/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def get_user_id(self, details, response):

def get_user_details(self, response):
"""Return user details from Google API account"""
if "email" in response:
email = response["email"]
else:
email = ""
email = response.get("email", "")

name, given_name, family_name = (
response.get("name", ""),
Expand Down
5 changes: 1 addition & 4 deletions social_core/backends/saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def get_attr(self, attributes, conf_key, default_attribute):
key = self.conf.get(conf_key, default_attribute)
value = attributes[key] if key in attributes else None
if isinstance(value, list):
if len(value):
value = value[0]
else:
value = None
value = value[0] if value else None
return value

@property
Expand Down
5 changes: 1 addition & 4 deletions social_core/pipeline/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def identity_func(val):

if do_slugify:
override_slug = strategy.setting("SLUGIFY_FUNCTION")
if override_slug:
slug_func = module_member(override_slug)
else:
slug_func = slugify
slug_func = module_member(override_slug) if override_slug else slugify
else:
slug_func = identity_func

Expand Down
7 changes: 2 additions & 5 deletions social_core/tests/backends/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ def handle_state(self, start_url, target_url):
start_query = parse_qs(urlparse(start_url).query)
redirect_uri = start_query.get("redirect_uri")

if getattr(self.backend, "STATE_PARAMETER", False):
if start_query.get("state"):
target_url = url_add_parameters(
target_url, {"state": start_query["state"]}
)
if getattr(self.backend, "STATE_PARAMETER", False) and start_query.get("state"):
target_url = url_add_parameters(target_url, {"state": start_query["state"]})

if redirect_uri and getattr(self.backend, "REDIRECT_STATE", False):
redirect_query = parse_qs(urlparse(redirect_uri).query)
Expand Down
5 changes: 1 addition & 4 deletions social_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ def user_is_authenticated(user):

def user_is_active(user):
if user and hasattr(user, "is_active"):
if callable(user.is_active):
is_active = user.is_active()
else:
is_active = user.is_active
is_active = user.is_active() if callable(user.is_active) else user.is_active
elif user:
is_active = True
else:
Expand Down

0 comments on commit e35d81e

Please sign in to comment.