Skip to content

Replace flake8-bugbear with Ruff #11500

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

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Since typeshed stubs them, they can still be expected to be found in a
# developer's venv for intellisense and reference reasons
# A flake8-builtins
# B flake8-bugbear
# D flake8-docstrings
# N8 pep8-naming
# SIM flake8-simplify
Expand All @@ -17,7 +18,6 @@
# E701 Multiple statements on one line (colon) -- disallows "..." on the same line

# Some rules are considered irrelevant to stub files:
# B All flake8-bugbear rules are .py-specific
# F401 imported but unused -- does not recognize re-exports
# https://github.com/PyCQA/pyflakes/issues/474

Expand All @@ -27,18 +27,18 @@
# F405 defined from star imports

[flake8]
extend-ignore = A, D, N8, SIM, RST, TYP, E301, E302, E305, E501, E701
extend-ignore = A, B, D, N8, SIM, RST, TYP, E301, E302, E305, E501, E701
per-file-ignores =
*.py: E203
*.pyi: B, E741, F401, F403, F405
*.pyi: E741, F401, F403, F405
# Since typing.pyi defines "overload" this is not recognized by Flake8 as typing.overload.
# Unfortunately, Flake8 does not allow to "noqa" just a specific error inside the file itself.
# https://github.com/PyCQA/flake8/issues/1079
# F811 redefinition of unused '...'
stdlib/typing.pyi: B, E741, F401, F403, F405, F811
stdlib/typing.pyi: E741, F401, F403, F405, F811
# Generated protobuf files include docstrings,
# and import some things from typing_extensions that could be imported from typing
*_pb2.pyi: B, E741, F401, F403, F405, Y021, Y023, Y026, Y053, Y054
*_pb2.pyi: E741, F401, F403, F405, Y021, Y023, Y026, Y053, Y054

exclude = .venv*,.git
noqa_require_code = true
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ repos:
hooks:
- id: flake8
additional_dependencies:
- "flake8-bugbear==24.1.17" # must match requirements-tests.txt
- "flake8-noqa==1.4.0" # must match requirements-tests.txt
- "flake8-pyi==24.1.0" # must match requirements-tests.txt
types: [file]
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ you're free to do so. Either run the following manually...

Our code is also linted using [`Flake8`](https://github.com/pycqa/flake8),
with plugins [`flake8-pyi`](https://github.com/pycqa/flake8-pyi),
[`flake8-bugbear`](https://github.com/PyCQA/flake8-bugbear),
and [`flake8-noqa`](https://github.com/plinss/flake8-noqa).
As with our other checks, running
Flake8 before filing a PR is not required. However, if you wish to run Flake8
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exclude = [

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"FA", # flake8-future-annotations
"I", # isort
# Only enable rules that have safe autofixes:
Expand All @@ -49,6 +50,13 @@ select = [
"UP039", # don't use parens after a class definition with no bases
]

[tool.ruff.lint.per-file-ignores]
"*.pyi" = [
# Most flake8-bugbear rules don't apply for third-party stubs like typeshed,
# B033 could be slightly useful but Ruff doesn't have per-file select
"B", # flake8-bugbear
]

[tool.ruff.lint.isort]
split-on-trailing-comma = false
combine-as-imports = true
Expand Down
2 changes: 1 addition & 1 deletion pyrightconfig.testcases.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See https://github.com/python/typeshed/pull/8083
"enableTypeIgnoreComments": true,
// If a test case uses this anti-pattern, there's likely a reason and annoying to `type: ignore`.
// Let flake8-bugbear flag it (B006)
// Let Ruff flag it (B006)
"reportCallInDefaultInitializer": "none",
// Too strict and not needed for type testing
"reportMissingSuperCall": "none",
Expand Down
1 change: 0 additions & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# "tool.typeshed" section in pyproject.toml for additional type checkers.
black==24.1.1 # must match .pre-commit-config.yaml
flake8==7.0.0 # must match .pre-commit-config.yaml
flake8-bugbear==24.1.17 # must match .pre-commit-config.yaml
flake8-noqa==1.4.0 # must match .pre-commit-config.yaml
flake8-pyi==24.1.0 # must match .pre-commit-config.yaml
mypy==1.8.0
Expand Down
2 changes: 1 addition & 1 deletion scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def from_cmd_arg(cls, cmd_arg: str) -> ActionLevel:
try:
return cls[cmd_arg]
except KeyError:
raise argparse.ArgumentTypeError(f'Argument must be one of "{list(cls.__members__)}"')
raise argparse.ArgumentTypeError(f'Argument must be one of "{list(cls.__members__)}"') from None

nothing = 0, "make no changes"
local = 1, "make changes that affect local repo"
Expand Down
2 changes: 1 addition & 1 deletion tests/check_consistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# These type checkers and linters must have exact versions in the requirements file to ensure
# consistent CI runs.
linters = {"black", "flake8", "flake8-bugbear", "flake8-noqa", "flake8-pyi", "ruff", "mypy", "pytype"}
linters = {"black", "flake8", "flake8-noqa", "flake8-pyi", "ruff", "mypy", "pytype"}


def assert_consistent_filetypes(
Expand Down