From c415324932dd95f52c2292fe6abc8d08697b898b Mon Sep 17 00:00:00 2001 From: george Date: Sun, 6 Feb 2022 20:37:43 +0000 Subject: [PATCH] Add flake8-bugbear --- .flake8 | 4 +--- .pre-commit-config.yaml | 2 +- app/dashboard/views/domain_detail.py | 2 +- app/email_utils.py | 2 +- app/models.py | 2 +- app/spamassassin_utils.py | 2 +- poetry.lock | 21 ++++++++++++++++++++- pyproject.toml | 2 +- tests/api/test_serializer.py | 2 +- tests/dashboard/test_index.py | 2 +- tests/test_models.py | 2 +- 11 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.flake8 b/.flake8 index a5cb3664..3c546697 100644 --- a/.flake8 +++ b/.flake8 @@ -6,9 +6,7 @@ extend-ignore = E203, E501, # Ignore "f-string is missing placeholders" - F541, - # allow bare "except" - E722 + F541 exclude = .git, __pycache__, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6f438cf8..99664765 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: hooks: - id: black language_version: python3.7 -- repo: https://gitlab.com/pycqa/flake8 +- repo: https://github.com/pycqa/flake8 rev: 4.0.1 hooks: - id: flake8 diff --git a/app/dashboard/views/domain_detail.py b/app/dashboard/views/domain_detail.py index cea36ff4..c97a110d 100644 --- a/app/dashboard/views/domain_detail.py +++ b/app/dashboard/views/domain_detail.py @@ -440,7 +440,7 @@ def domain_detail_auto_create(custom_domain_id): try: re.compile(new_auto_create_rule_form.regex.data) - except: + except Exception: flash( f"Invalid regex {new_auto_create_rule_form.regex.data}", "error", diff --git a/app/email_utils.py b/app/email_utils.py index 43c8f34d..eb6117ad 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -823,7 +823,7 @@ def copy(msg: Message) -> Message: LOG.w("deepcopy fails, try string parsing") try: return message_from_string(msg.as_string()) - except (UnicodeEncodeError, KeyError, LookupError): + except (UnicodeEncodeError, LookupError): LOG.w("as_string() fails, try bytes parsing") return message_from_bytes(to_bytes(msg)) diff --git a/app/models.py b/app/models.py index 3b8b9423..40bc0227 100644 --- a/app/models.py +++ b/app/models.py @@ -1323,7 +1323,7 @@ class Alias(Base, ModelMixin): raise Exception("alias prefix cannot be empty") # find the right suffix - avoid infinite loop by running this at max 1000 times - for i in range(1000): + for _ in range(1000): suffix = user.get_random_alias_suffix() email = f"{prefix}.{suffix}@{FIRST_ALIAS_DOMAIN}" diff --git a/app/spamassassin_utils.py b/app/spamassassin_utils.py index 97d79385..f1e2d54c 100644 --- a/app/spamassassin_utils.py +++ b/app/spamassassin_utils.py @@ -95,7 +95,7 @@ class SpamAssassin(object): # join line when current one is only wrap of previous tablelists_temp = [] if tablelists: - for counter, tablelist in enumerate(tablelists): + for _, tablelist in enumerate(tablelists): if len(tablelist) > 1: if (tablelist[0].isnumeric() or tablelist[0] == "-") and ( tablelist[1].isnumeric() or tablelist[1] == "." diff --git a/poetry.lock b/poetry.lock index aa8b2120..450ebd53 100644 --- a/poetry.lock +++ b/poetry.lock @@ -463,6 +463,21 @@ mccabe = ">=0.6.0,<0.7.0" pycodestyle = ">=2.8.0,<2.9.0" pyflakes = ">=2.4.0,<2.5.0" +[[package]] +name = "flake8-bugbear" +version = "22.1.11" +description = "A plugin for flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle." +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +attrs = ">=19.2.0" +flake8 = ">=3.0.0" + +[package.extras] +dev = ["coverage", "hypothesis", "hypothesmith (>=0.2)", "pre-commit"] + [[package]] name = "flanker" version = "0.9.11" @@ -1941,7 +1956,7 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "1aefbb220007ba7c9a6ab01652e298942996f14da63fe18e13f2dfcdb15cc41c" +content-hash = "078a49e90e6d61fbb0673113c6300dd06ab5faa9a6fcc7264914fa32e21b8f5c" [metadata.files] aiohttp = [ @@ -2224,6 +2239,10 @@ flake8 = [ {file = "flake8-4.0.1-py2.py3-none-any.whl", hash = "sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d"}, {file = "flake8-4.0.1.tar.gz", hash = "sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d"}, ] +flake8-bugbear = [ + {file = "flake8-bugbear-22.1.11.tar.gz", hash = "sha256:4c2a4136bd4ecb8bf02d5159af302ffc067642784c9d0488b33ce4610da825ee"}, + {file = "flake8_bugbear-22.1.11-py3-none-any.whl", hash = "sha256:ce7ae44aaaf67ef192b8a6de94a5ac617144e1675ad0654fdea556f48dc18d9b"}, +] flanker = [ {file = "flanker-0.9.11.tar.gz", hash = "sha256:974418e5b498fd3bcb3859c22e22d26495257f9cf98b744c17f2335aca86e001"}, ] diff --git a/pyproject.toml b/pyproject.toml index e78a099c..8d59c897 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,8 +91,8 @@ pytest-cov = "^3.0.0" pre-commit = "^2.17.0" black = "^22.1.0" flake8 = "^4.0.1" +flake8-bugbear = "^22.1.11" [build-system] requires = ["poetry>=0.12"] build-backend = "poetry.masonry.api" - diff --git a/tests/api/test_serializer.py b/tests/api/test_serializer.py index 0adba539..b8e2c27a 100644 --- a/tests/api/test_serializer.py +++ b/tests/api/test_serializer.py @@ -179,7 +179,7 @@ def test_get_alias_infos_pinned_alias(flask_client): ) # to have 3 pages: 2*PAGE_LIMIT + the alias automatically created for a new account - for i in range(2 * PAGE_LIMIT): + for _ in range(2 * PAGE_LIMIT): Alias.create_new_random(user) first_alias = Alias.order_by(Alias.id).first() diff --git a/tests/dashboard/test_index.py b/tests/dashboard/test_index.py index 01b20a22..0c25e73f 100644 --- a/tests/dashboard/test_index.py +++ b/tests/dashboard/test_index.py @@ -23,7 +23,7 @@ def test_too_many_requests(flask_client): login(flask_client) # can't create more than 5 aliases in 1 minute - for i in range(7): + for _ in range(7): r = flask_client.post( url_for("dashboard.index"), data={"form-name": "create-random-email"}, diff --git a/tests/test_models.py b/tests/test_models.py index d86f9cdf..2506f476 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -52,7 +52,7 @@ def test_suggested_emails_for_user_who_cannot_create_new_alias(flask_client): ) # make sure user runs out of quota to create new email - for i in range(MAX_NB_EMAIL_FREE_PLAN): + for _ in range(MAX_NB_EMAIL_FREE_PLAN): Alias.create_new(user=user, prefix="test") Session.commit()