Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable flake8-bugbear rules via ruff #7403

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Enable flake8-bugbear rules via ruff #7403

wants to merge 5 commits into from

Conversation

legoktm
Copy link
Member

@legoktm legoktm commented Jan 6, 2025

Status

Ready for review

Description of Changes

Upgrade ruff to 0.8.6

Switch to f-string and remove no-longer needed override.

Enable flake8-bugbear rules via ruff

Address most of the issues found by the flake8-bugbear rules,
and suppress a few that aren't worth fixing right now. The remaining
ones will be fixed in follow-up commits.

Don't use finally to return a redirect

As described in
https://docs.astral.sh/ruff/rules/jump-statement-in-finally/ and more
recently in https://peps.python.org/pep-0765/, using return in a
finally block has the potential of suppressing exceptions.

Given that in both cases we have a blanket exception handler, it should
be safe to return outside of a finally. If there are exceptions being
suppressed, we should surface them.

pretty_bad_protocol: Suppress warning about modifying os.environ

As described in
https://docs.astral.sh/ruff/rules/assignment-to-os-environ/, assigning
to os.environ doesn't actually clear the environment (i.e. remove keys
that are not set in the new value).

I think it is better to just explicitly suppress the warning since the
existing code works and isn't worth modifying.

Have migration test actually fail if value isn't missing

flake8-bugbear noticed that the second loop was checking the wrong
value. I noticed that the test wouldn't actually fail if the expected
exception wasn't raised, so use pytest.raises, which will correctly fail
if it doesn't work as expected.

Testing

How should the reviewer test this PR?

  • visual review
  • CI passes

Deployment

Any special considerations for deployment? n/a

Checklist

  • Linting (make lint) and tests (make test) pass in the development container
  • Linting and tests (make -C admin test) pass in the admin development container

Switch to f-string and remove no-longer needed override.
Address most of the issues found by the flake8-bugbear rules,
and suppress a few that aren't worth fixing right now. The remaining
ones will be fixed in follow-up commits.
As described in
<https://docs.astral.sh/ruff/rules/jump-statement-in-finally/> and more
recently in <https://peps.python.org/pep-0765/>, using return in a
finally block has the potential of suppressing exceptions.

Given that in both cases we have a blanket exception handler, it should
be safe to return outside of a finally. If there are exceptions being
suppressed, we should surface them.
As described in
<https://docs.astral.sh/ruff/rules/assignment-to-os-environ/>, assigning
to os.environ doesn't actually clear the environment (i.e. remove keys
that are not set in the new value).

I think it is better to just explicitly suppress the warning since the
existing code works and isn't worth modifying.
flake8-bugbear noticed that the second loop was checking the wrong
value. I noticed that the test wouldn't actually fail if the expected
exception wasn't raised, so use pytest.raises, which will correctly fail
if it doesn't work as expected.
@legoktm legoktm requested a review from a team as a code owner January 6, 2025 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant