Do extra code style checks with flake8-bugbear

Flake8 Bugbear checks for some extra things that aren’t code style
errors, but are likely to introduce bugs or unexpected behaviour. A
good example is having mutable default function arguments, which get
shared between every call to the function and therefore mutating a value
in one place can unexpectedly cause it to change in another.

This commit enables all the extra warnings provided by Flake8 Bugbear,
except for:
- the line length one (because we already lint for that separately)
- B903 Data class should either be immutable or use `__slots__` because
  this seems to false-positive on some of our custom exceptions
- B902 Invalid first argument 'cls' used for instance method because
  some SQLAlchemy decorators (eg `declared_attr`) make things that
  aren’t formally class methods take a class not an instance as their
  first argument

It disables:
- _B306: BaseException.message is removed in Python 3_ because I think
  our exceptions have a custom structure that means the `.message`
  attribute is still present

Matches the work done in other repos:
- https://github.com/alphagov/notifications-admin/pull/3172/files
This commit is contained in:
Chris Hill-Scott
2020-12-22 16:26:45 +00:00
parent 7152ac7cba
commit 3b0b96834d
29 changed files with 88 additions and 68 deletions
@@ -73,7 +73,7 @@ def test_add_reply_to_email_address_for_service_creates_another_email_for_servic
elif x.email_address == 'second@address.com':
assert not x.is_default
else:
assert False
raise AssertionError()
def test_add_reply_to_email_address_new_reply_to_is_default_existing_reply_to_is_not(notify_db_session):
@@ -89,7 +89,7 @@ def test_add_reply_to_email_address_new_reply_to_is_default_existing_reply_to_is
elif x.email_address == 'second@address.com':
assert x.is_default
else:
assert False
raise AssertionError()
def test_add_reply_to_email_address_can_add_a_third_reply_to_address(sample_service):
@@ -112,7 +112,7 @@ def test_add_reply_to_email_address_can_add_a_third_reply_to_address(sample_serv
elif x.email_address == 'third@address.com':
assert not x.is_default
else:
assert False
raise AssertionError()
def test_add_reply_to_email_address_ensures_first_reply_to_is_default(sample_service):
@@ -161,7 +161,7 @@ def test_update_reply_to_email_address_set_updated_to_default(sample_service):
elif x.email_address == 'first@address.com':
assert not x.is_default
else:
assert False
raise AssertionError()
def test_update_reply_to_email_address_raises_exception_if_single_reply_to_and_setting_default_to_false(sample_service):