ruff/crates/ruff_linter/resources/test/fixtures
Loïc Riegel 9490fbf1e1
[`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->
Closes #17347

Goal is to detect the useless exception statement not just for builtin
exceptions but also custom (user defined) ones.

## Test Plan

<!-- How was it tested? -->
I added test cases in the rule fixture and updated the insta snapshot.
Note that I first moved up a test case case which was at the bottom to
the correct "violation category".
I wasn't sure if I should create new test cases or just insert inside
those tests. I know that ideally each test case should test only one
thing, but here, duplicating twice 12 test cases seemed very verbose,
and actually less maintainable in the future. The drawback is that the
diff in the snapshot is hard to review, sorry. But you can see that the
snapshot gives 38 diagnostics, which is what we expect.

Alternatively, I also created this file for manual testing.
```py
# tmp/test_error.py

class MyException(Exception):
    ...
class MyBaseException(BaseException):
    ...
class MyValueError(ValueError):
    ...
class MyExceptionCustom(Exception):
    ...
class MyBaseExceptionCustom(BaseException):
    ...
class MyValueErrorCustom(ValueError):
    ...
class MyDeprecationWarning(DeprecationWarning):
    ...
class MyDeprecationWarningCustom(MyDeprecationWarning):
    ...
class MyExceptionGroup(ExceptionGroup):
    ...
class MyExceptionGroupCustom(MyExceptionGroup):
    ...
class MyBaseExceptionGroup(ExceptionGroup):
    ...
class MyBaseExceptionGroupCustom(MyBaseExceptionGroup):
    ...


def foo():
    Exception("...")
    BaseException("...")
    ValueError("...")
    RuntimeError("...")
    DeprecationWarning("...")
    GeneratorExit("...")
    SystemExit("...")
    ExceptionGroup("eg", [ValueError(1), TypeError(2), OSError(3), OSError(4)])
    BaseExceptionGroup("eg", [ValueError(1), TypeError(2), OSError(3), OSError(4)])
    MyException("...")
    MyBaseException("...")
    MyValueError("...")
    MyExceptionCustom("...")
    MyBaseExceptionCustom("...")
    MyValueErrorCustom("...")
    MyDeprecationWarning("...")
    MyDeprecationWarningCustom("...")
    MyExceptionGroup("...")
    MyExceptionGroupCustom("...")
    MyBaseExceptionGroup("...")
    MyBaseExceptionGroupCustom("...")

```

and you can run this to check the PR:
```sh
target/debug/ruff check tmp/test_error.py --select PLW0133 --unsafe-fixes --diff --no-cache --isolated --target-version py310
target/debug/ruff check tmp/test_error.py --select PLW0133 --unsafe-fixes --diff --no-cache --isolated --target-version py314
```
2025-12-09 13:49:55 -05:00
..
airflow [`airflow`] extend deprecated argument `concurrency` in `airflow..DAG` (`AIR301`) (#21220) 2025-11-03 15:20:20 -05:00
control-flow-graph [`pylint`] Fix `unreachable` infinite loop (`PLW0101`) (#15278) 2025-01-08 09:45:04 -06:00
eradicate Don't flag `pyrefly` pragmas as unused code (`ERA001`) (#19731) 2025-08-04 10:15:37 +02:00
fastapi [`fastapi`] Handle ellipsis defaults in FAST002 autofix (`FAST002`) (#20810) 2025-10-21 02:47:13 +00:00
filesystem Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
flake8_2020 Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
flake8_annotations [`flake8-annotations`] Fix return type annotations to handle shadowed builtin symbols (`ANN201`, `ANN202`, `ANN204`, `ANN205`, `ANN206`) (#20612) 2025-10-02 22:44:06 +00:00
flake8_async [`flake8-async`] Implement `blocking-path-method` (`ASYNC240`) (#20264) 2025-09-23 08:30:47 -04:00
flake8_bandit [flake8-bandit] Fix false positive when using non-standard `CSafeLoader` path (S506). (#21830) 2025-12-07 11:40:46 +01:00
flake8_blind_except [`flake8-blind-except`] Fix `BLE001` false-positive on `raise ... from None` (#19755) 2025-08-13 13:01:47 -04:00
flake8_boolean_trap FBT001: exclude boolean operators (#14203) 2024-11-10 22:40:37 +00:00
flake8_bugbear [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823) 2025-12-08 14:00:43 -05:00
flake8_builtins [`flake8-bultins`] Detect class-scope builtin shadowing in decorators, default args, and attribute initializers (`A003`) (#20178) 2025-09-22 18:12:45 -04:00
flake8_commas Track t-strings and f-strings for token-based rules and suppression comments (#20357) 2025-09-12 13:00:12 -05:00
flake8_comprehensions [`flake8-comprehensions`] Preserve trailing commas for single-element lists (`C409`) (#19571) 2025-09-19 09:27:14 -04:00
flake8_datetimez [`flake8-datetime`] Ignore `.replace()` calls while looking for `.astimezone` (#16050) 2025-02-09 15:48:59 +00:00
flake8_debugger [`flake8-debugger`] Also flag `sys.breakpointhook` and `sys.__breakpointhook__` (`T100`) (#16191) 2025-02-16 14:50:16 -05:00
flake8_django [`flake8-django`] Apply `DJ001` to annotated fields (#20907) 2025-10-27 09:19:15 +01:00
flake8_errmsg [`flake8-errmsg`] Exclude `typing.cast` from `EM101` (#19656) 2025-08-01 13:37:44 -04:00
flake8_executable [`flake8-executable`] Allow `uvx` in shebang line (`EXE003`) (#18967) 2025-06-30 09:38:18 -04:00
flake8_fixme Fix TODO directive out of bounds acccess (#13756) 2024-10-15 10:49:53 +02:00
flake8_future_annotations [`ruff`] Extend FA102 with listed PEP 585-compatible APIs (#20659) 2025-10-03 09:45:32 -04:00
flake8_gettext [`flake8-gettext`] Resolve qualified names and built-in bindings (`INT001`, `INT002`, `INT003`) (#19045) 2025-10-20 18:24:55 -04:00
flake8_implicit_str_concat [`flake8-implicit-str-concat`] Avoid invalid fix generated by autofix (`ISC003`) (#21517) 2025-11-21 17:22:35 -08:00
flake8_import_conventions [flake8-import-conventions] Add import `numpy.typing as npt` to default `flake8-import-conventions.aliases` (#17133) 2025-04-02 09:25:46 +02:00
flake8_logging [`flake8-logging`] Avoid false positive for `exc_info=True` outside `logger.exception` (`LOG014`) (#18737) 2025-06-20 14:43:08 -04:00
flake8_logging_format [`flake8-logging-format`] Avoid dropping implicitly concatenated pieces in the `G004` fix (#20793) 2025-10-09 18:14:38 -04:00
flake8_no_pep420 Skip namespace package enforcement for PEP 723 scripts (#13974) 2024-10-29 02:11:31 +00:00
flake8_pie Fix F701 to F707 errors in tests (#19125) 2025-07-04 13:43:18 -05:00
flake8_print Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
flake8_pyi [`flake8-pyi`] Fix PYI034 to not trigger on metaclasses (`PYI034`) (#20881) 2025-10-24 13:40:26 +00:00
flake8_pytest_style Less confidently mark f-strings as empty when inferring truthiness (#20152) 2025-08-29 22:12:54 +00:00
flake8_quotes Implement template strings (#17851) 2025-05-30 15:00:56 -05:00
flake8_raise [`flake8-raise`] Make fix unsafe if it deletes comments (`RSE102`) (#18788) 2025-06-21 19:09:40 +02:00
flake8_return [`flake8-return`] Fix false-positive for variables used inside nested functions in `RET504` (#18433) 2025-07-10 16:10:22 -04:00
flake8_self [`flake8-self`] Ignore attribute accesses on instance-like variables (`SLF001`) (#16149) 2025-02-23 10:00:49 +00:00
flake8_simplify [`flake8-simplify`] Fix truthiness assumption for non-iterable arguments in tuple/list/set calls (`SIM222`, `SIM223`) (#21479) 2025-12-01 16:57:51 -05:00
flake8_slots Avoid recommending `__slots__` for classes that inherit from more than `namedtuple` (#12531) 2024-07-26 14:24:40 +00:00
flake8_tidy_imports Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
flake8_todos [`flake8-todos`] Allow VSCode GitHub PR extension style links in `missing-todo-link` (`TD003`) (#15519) 2025-01-15 23:47:33 +00:00
flake8_type_checking [`flake8-type-checking`] Fix `TC003` false positive with `future-annotations` (#21125) 2025-10-30 14:14:29 -04:00
flake8_unused_arguments Add t-string fixtures for rules that do not need to be modified (#19146) 2025-07-14 09:46:31 -05:00
flake8_use_pathlib [`flake8-use-pathlib`] Fix `PTH101`, `PTH104`, `PTH105`, `PTH121` fixes (#20143) 2025-09-18 14:17:54 +00:00
flynt [`flynt`] Fix f-string quoting for mixed quote joiners (`FLY002`) (#20662) 2025-10-03 09:15:57 -04:00
isort [`isort`] Fix inserting required imports before future imports (`I002`) (#20676) 2025-10-06 13:40:36 +00:00
mccabe Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
numpy Ignore `NPY201` inside `except` blocks for compatibility with older numpy versions (#12490) 2024-07-24 20:03:23 +00:00
pandas_vet Limit inplace diagnostics to methods that accept inplace (#9495) 2024-01-12 14:12:54 -05:00
pep8_naming [`pep8-naming`] Fix `N802` false positives for `CGIHTTPRequestHandler` and `SimpleHTTPRequestHandler` (#19432) 2025-07-23 12:04:11 -04:00
perflint [`perflint`] Handle tuples in dictionary comprehensions (`PERF403`) (#19934) 2025-08-28 21:37:40 +00:00
pycodestyle [`pycodestyle`] Fix `E301` to only trigger for functions immediately within a class (#19768) 2025-09-16 11:00:07 -04:00
pydoclint [`pydoclint`] Fix false positive when Sphinx directives follow Raises section (`DOC502`) (#20535) 2025-11-12 21:37:55 +00:00
pydocstyle [`pydocstyle`] Suppress `D417` for parameters with `Unpack` annotations (#21816) 2025-12-08 19:00:05 +00:00
pyflakes Fix syntax error false positives for `await` outside functions (#21763) 2025-12-02 21:02:02 +00:00
pygrep_hooks [`pygrep_hooks`] Add `AsyncMock` methods to `invalid-mock-access` (`PGH005`) (#18547) 2025-06-24 17:27:21 -04:00
pylint [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382) 2025-12-09 13:49:55 -05:00
pyupgrade [`pyupgrade`] Fix false positive on relative imports from local `.builtins` module (`UP029`) (#21309) 2025-11-07 16:01:52 +00:00
refurb [`refurb`] Fix `FURB103` autofix (#21454) 2025-11-16 09:32:41 +01:00
ruff New diagnostics for unused range suppressions (#21783) 2025-12-09 08:30:27 -08:00
semantic_errors [semantic error tests]: refactor semantic error tests to separate files (#20926) 2025-10-27 21:18:11 +00:00
syntax_errors [`flake8-bugbear`] Catch `yield` expressions within other statements (`B901`) (#21200) 2025-12-03 12:05:15 -05:00
tryceratops Recode `TRY302` to `TRY203` (#13502) 2024-10-17 16:35:12 +01:00
__init__.py [`pylint`] (Re-)Implement `import-private-name` (`C2701`) (#9553) 2024-01-16 14:03:11 -05:00