Skip to content

Commit

Permalink
Formatting and linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
willbarton committed Jul 5, 2024
1 parent ebb818a commit 9b8bf5b
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
4 changes: 1 addition & 3 deletions flags/conditions/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def decorator(fn):
# Don't be a decorator, just register
if condition_name in _conditions:
raise DuplicateCondition(
'Flag condition "{name}" already registered.'.format(
name=condition_name
)
f'Flag condition "{condition_name}" already registered.'
)

# We attach the validator to the callable to allow for both a single source
Expand Down
12 changes: 6 additions & 6 deletions flags/conditions/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ def validate_boolean(value):
message = "Enter one of 'on', 'off', 'true', 'false', etc."
try:
strtobool(value)
except ValueError:
except ValueError as err:
# This was a string with an invalid boolean value
raise ValidationError(message)
except AttributeError:
raise ValidationError(message) from err
except AttributeError as err:
# This was not a string
if not isinstance(value, (int, bool)):
raise ValidationError(message)
raise ValidationError(message) from err


def validate_user(value):
UserModel = get_user_model()

try:
UserModel.objects.get(**{UserModel.USERNAME_FIELD: value})
except UserModel.DoesNotExist:
raise ValidationError("Enter the username of a valid user.")
except UserModel.DoesNotExist as err:
raise ValidationError("Enter the username of a valid user.") from err


def validate_date(value):
Expand Down
4 changes: 2 additions & 2 deletions flags/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def clean_value(self):
if validator is not None:
try:
validator(value)
except Exception as e:
raise forms.ValidationError(e)
except Exception as err:
raise forms.ValidationError(err) from err

return value

Expand Down
4 changes: 2 additions & 2 deletions flags/management/commands/disable_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def add_arguments(self, parser):
def handle(self, *args, **options):
try:
disable_flag(options["flag_name"])
except KeyError as e:
raise CommandError(e)
except KeyError as err:
raise CommandError(err) from err

self.stdout.write(
self.style.SUCCESS(f"Successfully disabled {options['flag_name']}")
Expand Down
4 changes: 2 additions & 2 deletions flags/management/commands/enable_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def add_arguments(self, parser):
def handle(self, *args, **options):
try:
enable_flag(options["flag_name"])
except KeyError as e:
raise CommandError(e)
except KeyError as err:
raise CommandError(err) from err

self.stdout.write(
self.style.SUCCESS(f"Successfully enabled {options['flag_name']}")
Expand Down
1 change: 1 addition & 0 deletions flags/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ def __init__(self, get_response):
"FlagConditionsMiddleware is deprecated and no longer has any "
"effect. It will be removed in a future version of Django-Flags. ",
FutureWarning,
stacklevel=2,
)
raise MiddlewareNotUsed
17 changes: 8 additions & 9 deletions flags/templatetags/flags_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ def state_str(flag):

# If there are non-required conditions, we should say something about
# them too.
if not is_enabled:
if len(non_bool_conditions) > len(req_conditions):
if len(req_conditions) > 0:
state_str += _(" and")
state_str += _(" <i>any</i>")
if len(req_conditions) > 0:
state_str += _(" non-required")
state_str += _(" condition is met")
if not is_enabled and len(non_bool_conditions) > len(req_conditions):
if len(req_conditions) > 0:
state_str += _(" and")
state_str += _(" <i>any</i>")
if len(req_conditions) > 0:
state_str += _(" non-required")
state_str += _(" condition is met")

# Finally, if there are no non-boolean conditions and no required boolean
# conditions, we can just say it's enabled or disabled for all requests.
Expand All @@ -96,4 +95,4 @@ def state_str(flag):
# Full stop.
state_str += "."

return mark_safe(state_str)
return mark_safe(state_str) # nosec B703, B308
7 changes: 4 additions & 3 deletions flags/tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import os

from django.urls import include, path

import debug_toolbar

from flags.conditions import register


Expand Down Expand Up @@ -77,9 +81,6 @@ def kwarg_condition(expected_value, passed_value=None, **kwargs):
# DEBUG=True
# INTERNAL_IPS=['127.0.0.1']
ROOT_URLCONF = __name__
from django.urls import include, path

import debug_toolbar


urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion flags/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def fallback(request):
decorator(view)

self.assertTrue(
any(item.category == RuntimeWarning for item in warning_list)
any(item.category is RuntimeWarning for item in warning_list)
)

def test_view_fallback_same_args(self):
Expand Down
2 changes: 1 addition & 1 deletion flags/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_deprecated_condition_attr(self):
response = view(self.request())

self.assertTrue(
any(item.category == FutureWarning for item in warning_list)
any(item.category is FutureWarning for item in warning_list)
)

self.assertContains(response, "ok")
1 change: 1 addition & 0 deletions flags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def as_view(cls, **initkwargs):
"will be removed in a future version of Django-Flags. "
"Please use the state attribute instead.",
FutureWarning,
stacklevel=2,
)
state = condition

Expand Down

0 comments on commit 9b8bf5b

Please sign in to comment.