lint: Enforce consistent style of using transaction.atomic decorator.

When decorating a function, @transaction.atomic and
@transaction.atomic() are equivalent. We can add a linting rule to
enforce consistency.
This commit is contained in:
Mateusz Mandera 2021-12-12 19:13:36 +01:00 committed by Tim Abbott
parent bc3d03730f
commit 323f5dbba2
2 changed files with 5 additions and 1 deletions

View File

@ -21,7 +21,7 @@ def set_expiry_date_for_existing_confirmations(
UNSUBSCRIBE = 4
MULTIUSE_INVITE = 6
@transaction.atomic()
@transaction.atomic
def backfill_confirmations_between(lower_bound: int, upper_bound: int) -> None:
confirmations = Confirmation.objects.filter(id__gte=lower_bound, id__lte=upper_bound)
for confirmation in confirmations:

View File

@ -481,6 +481,10 @@ python_rules = RuleList(
"pattern": "\\.(called(_once|_with|_once_with)?|not_called|has_calls|not_called)[(]",
"description": 'A mock function is missing a leading "assert_"',
},
{
"pattern": "@transaction.atomic\\(\\)",
"description": "Use @transaction.atomic as function decorator for consistency.",
},
*whitespace_rules,
],
max_length=110,