From 9059300f0f279c3963f51f17dc65670e2aadf308 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 29 Feb 2024 00:06:37 -0500 Subject: [PATCH 1/6] use Ruff instead of flake8-bugbear --- .flake8 | 7 +++---- .pre-commit-config.yaml | 1 - CONTRIBUTING.md | 1 - pyproject.toml | 7 +++++++ pyrightconfig.testcases.json | 2 +- requirements-tests.txt | 1 - scripts/stubsabot.py | 2 +- tests/check_consistent.py | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.flake8 b/.flake8 index e07faf68fdc2..de77d5986758 100644 --- a/.flake8 +++ b/.flake8 @@ -17,7 +17,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 @@ -30,15 +29,15 @@ extend-ignore = A, 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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8d2cee56233..9bf998ec4bdd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bc3aeefb8d5a..1dd7fd6fdb84 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index c3e1cdd1c112..88318be9819f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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: @@ -49,6 +50,12 @@ select = [ "UP039", # don't use parens after a class definition with no bases ] +[tool.ruff.lint.extend-per-file-ignores] +"*.pyi" = [ + # Rules that are out of the control of stub authors: + "B006", # Do not use mutable data structures for argument defaults +] + [tool.ruff.lint.isort] split-on-trailing-comma = false combine-as-imports = true diff --git a/pyrightconfig.testcases.json b/pyrightconfig.testcases.json index 059df46cc608..e2898dd56268 100644 --- a/pyrightconfig.testcases.json +++ b/pyrightconfig.testcases.json @@ -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", diff --git a/requirements-tests.txt b/requirements-tests.txt index ab7cc475ff0b..b20110d2c17e 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -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 diff --git a/scripts/stubsabot.py b/scripts/stubsabot.py index b2a86e31d0f6..5f4f804830bd 100644 --- a/scripts/stubsabot.py +++ b/scripts/stubsabot.py @@ -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" diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 1fc40db576c9..1abb4d635148 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -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( From 154dbbcbbf4646bb70ba69a0153c66ad87347ffe Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 29 Feb 2024 02:26:51 -0500 Subject: [PATCH 2/6] Update .flake8 Co-authored-by: Alex Waygood --- .flake8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index de77d5986758..45b8b95900b4 100644 --- a/.flake8 +++ b/.flake8 @@ -26,7 +26,7 @@ # 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: E741, F401, F403, F405 From f18d07be9597c938bd4fb595f80dbc03d5b854e9 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 29 Feb 2024 12:32:30 -0500 Subject: [PATCH 3/6] Disable bugbear in pyi --- pyproject.toml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 88318be9819f..b341134b036b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,10 +50,11 @@ select = [ "UP039", # don't use parens after a class definition with no bases ] -[tool.ruff.lint.extend-per-file-ignores] +[tool.ruff.lint.per-file-ignores] "*.pyi" = [ - # Rules that are out of the control of stub authors: - "B006", # Do not use mutable data structures for argument defaults + # 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] From 81e3a488f6b1b4452a118f9956e5f8004b001000 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 29 Feb 2024 17:36:00 +0000 Subject: [PATCH 4/6] comment --- .flake8 | 1 + 1 file changed, 1 insertion(+) diff --git a/.flake8 b/.flake8 index 45b8b95900b4..58152bb95d9b 100644 --- a/.flake8 +++ b/.flake8 @@ -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 From 9df2be062a0ef6ba8a9a3794004776c78cd7be6c Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 29 Feb 2024 12:42:42 -0500 Subject: [PATCH 5/6] s2clientprotocol --- stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi index e954e46118e1..53553c043bbc 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi @@ -4,7 +4,7 @@ isort:skip_file """ import builtins import collections.abc -import sys +import typing as typing_extensions import google.protobuf.descriptor import google.protobuf.internal.containers @@ -12,11 +12,6 @@ import google.protobuf.message import s2clientprotocol.common_pb2 import s2clientprotocol.error_pb2 -if sys.version_info >= (3, 8): - import typing as typing_extensions -else: - import typing_extensions - DESCRIPTOR: google.protobuf.descriptor.FileDescriptor @typing_extensions.final From 6fc122ec50d1c5eec8170b3d9ff57de1165b2083 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 29 Feb 2024 12:43:52 -0500 Subject: [PATCH 6/6] Revert "s2clientprotocol" This reverts commit 9df2be062a0ef6ba8a9a3794004776c78cd7be6c. --- stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi b/stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi index 53553c043bbc..e954e46118e1 100644 --- a/stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi +++ b/stubs/s2clientprotocol/s2clientprotocol/query_pb2.pyi @@ -4,7 +4,7 @@ isort:skip_file """ import builtins import collections.abc -import typing as typing_extensions +import sys import google.protobuf.descriptor import google.protobuf.internal.containers @@ -12,6 +12,11 @@ import google.protobuf.message import s2clientprotocol.common_pb2 import s2clientprotocol.error_pb2 +if sys.version_info >= (3, 8): + import typing as typing_extensions +else: + import typing_extensions + DESCRIPTOR: google.protobuf.descriptor.FileDescriptor @typing_extensions.final