ruff/crates/ruff_linter/resources/test/fixtures/pylint
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
..
import_aliasing_2 [`pylint`] Ignore __init__.py files in (PLC0414) (#18400) 2025-06-20 18:20:27 +00:00
import_private_name [`pylint`] (Re-)Implement `import-private-name` (`C2701`) (#9553) 2024-01-16 14:03:11 -05:00
import_self Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
assert_on_string_literal.py Add t-string fixtures for rules that do not need to be modified (#19146) 2025-07-14 09:46:31 -05:00
await_outside_async.ipynb Fix `await-outside-async` to allow `await` at the top-level scope of a notebook (#14225) 2024-11-09 12:44:48 -05:00
await_outside_async.py [syntax-errors] `await` outside async functions (#17363) 2025-04-14 13:01:48 -04:00
bad_dunder_method_name.py [pylint] removed dunder methods in Python 3 (PLW3201) (#13194) 2024-09-04 08:23:08 +02:00
bad_open_mode.py Improve handling of builtin symbols in linter rules (#10919) 2024-04-16 11:37:31 +01:00
bad_staticmethod_argument.py Consider `__new__` methods as special function type for enforcing class method or static method rules (#13305) 2025-02-16 14:12:25 -06:00
bad_str_strip_call.py [`pylint`] Also report when the object isn't a literal (`PLE1310`) (#15985) 2025-02-10 09:31:27 +01:00
bad_string_format_character.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
bad_string_format_type.py Fix bug where `PLE1307` was raised when formatting `%c` with characters (#8407) 2023-11-02 04:36:52 +00:00
bidirectional_unicode.py [`pylint`] Add U+061C to `PLE2502` (#20106) 2025-08-28 16:35:48 -04:00
binary_op_exception.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
boolean_chained_comparison.py [`pylint`] Include parentheses and multiple comparators in check for `boolean-chained-comparison (PLR1716)` (#14781) 2024-12-08 22:58:45 -06:00
collapsible_else_if.py Preserve trivia (i.e. comments) in PLR5501 (#13573) 2024-10-03 10:22:20 -05:00
compare_to_empty_string.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
comparison_of_constant.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
comparison_with_itself.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
continue_in_finally.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
dict_index_missing_items.py [`pylint`] Implement `dict-iter-missing-items` (`C0206`) (#11688) 2024-06-06 00:28:01 -04:00
dict_iter_missing_items.py [`pylint`] Fix suppression for empty dict without tuple key annotation (`PLE1141`) (#21290) 2025-11-21 22:07:18 +00:00
duplicate_bases.py [`pylint`] Mark `PLE0241` autofix as unsafe if there's comments in the base classes (#18832) 2025-06-21 17:20:39 +00:00
empty_comment.py Avoid panic when comment is preceded by Unicode (#9331) 2023-12-31 12:54:31 +00:00
empty_comment_line_continuation.py [`pylint`] Handle empty comments after line continuation (`PLR2044`) (#19405) 2025-07-23 11:56:49 -04:00
eq_without_hash.py [`pylint`] Detect nested methods correctly (`PLW1641`) (#15032) 2024-12-30 16:55:14 +01:00
global_at_module_level.py [pylint] - implement `global-at-module-level` (`W0604`) (#8058) 2023-10-19 04:48:27 +00:00
global_statement.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
global_variable_not_assigned.py Track conditional deletions in the semantic model (#10415) 2024-03-14 20:45:46 -04:00
if_stmt_min_max.py [`pylint`] Make fix unsafe if it deletes comments (`PLR1730`) (#17459) 2025-04-18 12:49:01 -04:00
import_aliasing.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
import_outside_top_level.py Implement pylint import-outside-toplevel rule (C0415) (#5180) 2023-10-29 16:40:26 +00:00
import_outside_top_level_with_banned.py Honor banned top level imports by TID253 in PLC0415. (#15628) 2025-01-24 11:07:21 +01:00
invalid_all_format.py Allow named expressions in `__all__` assignments (#7673) 2023-09-27 00:36:55 -04:00
invalid_all_object.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
invalid_characters.py [`pylint`] Extend invalid string character rules to include t-strings (#19355) 2025-07-15 07:59:51 -05:00
invalid_characters_syntax_error.py Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
invalid_envvar_default.py Fix `PLW1508` false positive for default string created via a mult operation (#14841) 2024-12-08 18:25:47 +00:00
invalid_envvar_value.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
invalid_return_type_bool.py [`pylint`] Implement `invalid-bool-return-type` (`E304`) (#10377) 2024-03-13 19:43:45 +05:30
invalid_return_type_bytes.py Allow `NoReturn`-like functions for `__str__`, `__len__`, etc. (#11017) 2024-04-18 22:55:15 +00:00
invalid_return_type_hash.py [`pylint`] Implement `invalid-hash-returned` (`PLE0309`) (#10961) 2024-04-19 03:33:52 +00:00
invalid_return_type_index.py [`pylint`] Implement `invalid-index-returned` (`PLE0305`) (#10962) 2024-04-19 03:44:05 +00:00
invalid_return_type_length.py Allow `NoReturn`-like functions for `__str__`, `__len__`, etc. (#11017) 2024-04-18 22:55:15 +00:00
invalid_return_type_str.py Allow `NoReturn`-like functions for `__str__`, `__len__`, etc. (#11017) 2024-04-18 22:55:15 +00:00
iteration_over_set.py Respect hash-equivalent literals in `iteration-over-set` (#14063) 2024-11-03 18:44:52 +00:00
len_as_condition.py [`pylint`] Fix `PLC1802` autofix creating a syntax error and mark autofix as unsafe if there's comments in the `len` call (#18836) 2025-06-23 00:32:57 +00:00
literal_membership.py [`pylint`] Do not trigger `PLR6201` on empty collections (#15732) 2025-01-24 20:42:49 -06:00
load_before_global_declaration.py [`pylint`] Detect `global` declarations in module scope (`PLE0118`) (#17411) 2025-04-25 08:37:16 -04:00
logging_too_few_args.py Add `Expr::Name` checks to rules which use `is_logger_candidate` (#7521) 2023-09-27 00:21:22 +00:00
logging_too_many_args.py Add `Expr::Name` checks to rules which use `is_logger_candidate` (#7521) 2023-09-27 00:21:22 +00:00
magic_value_comparison.py `PLR2004`: Accept 0.0 and 1.0 as common magic values (#9964) 2024-02-13 01:21:06 +00:00
misplaced_bare_raise.py [pylint] Implement misplaced-bare-raise (E0704) (#7961) 2023-10-17 03:07:46 +00:00
misplaced_comparison_constant.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
missing_maxsplit_arg.py [`pylint`] Mark `PLC0207` fixes as unsafe when `*args` unpacking is present (#19679) 2025-08-06 14:19:49 -04:00
modified_iterating_set.py [`pylint`] Implement `modified-iterating-set` (`E4703`) (#10473) 2024-03-31 14:37:49 +00:00
named_expr_without_context.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
nan_comparison.py [`pylint`] Detect more exotic NaN literals in `PLW0177` (#18630) 2025-06-19 11:05:06 +00:00
nested_min_max.py [`pylint`] Allow fix with comments and document performance implications (`PLW3301`) (#18936) 2025-06-25 09:29:23 -04:00
no_method_decorator.py PLR0203: Delete entire statement, including semicolons (#10074) 2024-02-22 16:03:00 +00:00
no_self_use.py Add t-string fixtures for rules that do not need to be modified (#19146) 2025-07-14 09:46:31 -05:00
non_ascii_module_import.py [pylint] - Implement `non-ascii-module-import` (`C2403`) (#8056) 2023-10-20 18:06:22 +00:00
non_ascii_name.py [pylint] - implement `non-ascii-name` (`C2401`) (#8038) 2023-10-20 18:53:51 +00:00
non_augmented_assignment.py [`pylint`] Preserve original value format (`PLR6104`) (#14978) 2024-12-17 16:07:07 +01:00
non_slot_assignment.py [`pylint`] Ignore `__slots__` with dynamic values (#11488) 2024-05-22 04:18:01 +00:00
nonlocal_and_global.py [`pylint`] Implement `nonlocal-and-global` (`E115`) (#10407) 2024-03-18 00:43:02 +00:00
nonlocal_without_binding.py Add a `ScopeKind` for the `__class__` cell (#20048) 2025-08-26 09:49:08 -04:00
potential_index_error.py [`pylint`] Implement `potential-index-error` (`PLE0643`) (#9545) 2024-01-21 03:59:48 +00:00
property_with_parameters.py Consider more stdlib decorators to be property-like (#12583) 2024-07-30 17:18:23 +00:00
redeclared_assigned_name.py [pylint] Fix `PLW0128` to check assignment targets in square brackets and after asterisks (#18665) 2025-06-16 15:02:30 -04:00
redefined_argument_from_local.py Consider expression before statement when determining binding kind (#12346) 2024-07-16 14:49:26 +00:00
redefined_loop_name.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
redefined_slots_in_subclass.py [`pylint`] Implement `redefined-slots-in-subclass` (`W0244`) (#9640) 2025-01-17 09:54:15 -06:00
repeated_equality_comparison.py [`pylint`] - use sets when possible for `PLR1714` autofix (`repeated-equality-comparison`) (#14372) 2024-11-18 08:57:43 +01:00
repeated_keyword_argument.py Add Implementation for Pylint E1132: Repeated Keyword (#8706) 2023-11-19 00:26:24 +00:00
return_in_init.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
self_assigning_variable.py [`pylint`] Extend `self-assigning-variable` to multi-target assignments (#8839) 2023-11-25 18:42:19 +00:00
self_or_cls_assignment.py Consider `__new__` methods as special function type for enforcing class method or static method rules (#13305) 2025-02-16 14:12:25 -06:00
shallow_copy_environ.py [PLW1507] Mark fix unsafe (#16343) 2025-02-24 13:42:44 +01:00
single_string_slots.py Add t-string fixtures for rules that do not need to be modified (#19146) 2025-07-14 09:46:31 -05:00
singledispatch_method.py [`pylint`] Don't recommend decorating staticmethods with `@singledispatch` (`PLE1519`, `PLE1520`) (#10637) 2024-04-02 16:47:31 +00:00
singledispatchmethod_function.py [`pylint`] Don't recommend decorating staticmethods with `@singledispatch` (`PLE1519`, `PLE1520`) (#10637) 2024-04-02 16:47:31 +00:00
stop_iteration_return.py [`pylint`] Fix `PLR1708` false positives on nested functions (#21177) 2025-11-21 15:41:22 -05:00
subprocess_popen_preexec_fn.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
subprocess_run_without_check.py [`pylint`] Add fix for `subprocess-run-without-check` (`PLW1510`) (#6708) 2023-12-12 05:08:17 +00:00
super_without_brackets.py [pylint] - implement `super-without-brackets`/`W0245` (#9257) 2024-01-02 21:57:53 +00:00
sys_exit_alias_0.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_1.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_2.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_3.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_4.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_5.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_6.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_7.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_8.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_9.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_10.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_11.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
sys_exit_alias_12.py Avoid inserting imports directly after continuation (#7553) 2023-09-20 21:26:48 +00:00
sys_exit_alias_13.py [`pylint`] Convert a `code` keyword argument to a positional argument (`PLR1722`) (#16424) 2025-03-03 09:20:57 -05:00
sys_exit_alias_14.py [`pylint`] Convert a `code` keyword argument to a positional argument (`PLR1722`) (#16424) 2025-03-03 09:20:57 -05:00
sys_exit_alias_15.py [`pylint`] Convert a `code` keyword argument to a positional argument (`PLR1722`) (#16424) 2025-03-03 09:20:57 -05:00
sys_exit_alias_16.py [`pylint`] Convert a `code` keyword argument to a positional argument (`PLR1722`) (#16424) 2025-03-03 09:20:57 -05:00
too_many_arguments.py Consider `__new__` methods as special function type for enforcing class method or static method rules (#13305) 2025-02-16 14:12:25 -06:00
too_many_arguments_params.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
too_many_boolean_expressions.py [pylint] Implement PLR0916 (`too-many-boolean-expressions`) (#7975) 2023-10-17 04:44:25 +00:00
too_many_branches.py [`pylint`] Remove `try` body from branch counting (#11487) 2024-05-21 23:38:51 -04:00
too_many_branches_params.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
too_many_locals.py [`pylint`] Implement `too-many-locals` (`PLR0914`) (#9163) 2023-12-18 20:00:04 +00:00
too_many_nested_blocks.py [`pylint`] Implement `too-many-nested-blocks` (`PLR1702`) (#9172) 2024-01-24 19:30:01 +00:00
too_many_positional_arguments.py Consider `__new__` methods as special function type for enforcing class method or static method rules (#13305) 2025-02-16 14:12:25 -06:00
too_many_positional_params.py [`pylint`] Implement `too-many-positional` (`PLR0917`) (#8995) 2023-12-04 18:03:09 +00:00
too_many_public_methods.py [`pylint`] Ignore overload in `PLR0904` (#14730) 2024-12-02 14:36:51 +00:00
too_many_return_statements.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
too_many_return_statements_params.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
too_many_statements.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
too_many_statements_params.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
type_bivariance.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
type_name_incorrect_variance.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
type_param_name_mismatch.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
unexpected_special_method_signature.py [`pylint`] Fix false positives, add missing methods, and support positional-only parameters (`PLE0302`) (#16263) 2025-02-21 08:38:51 -05:00
unnecessary_dict_index_lookup.py [`pylint`] Recurse into subscript subexpressions when searching for list/dict lookups (`PLR1733`, `PLR1736`) (#13186) 2024-09-01 17:22:45 +01:00
unnecessary_direct_lambda_call.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
unnecessary_dunder_call.py [`pylint`] Fix `PLC2801` autofix creating a syntax error (#18857) 2025-06-23 10:15:53 -04:00
unnecessary_lambda.py [`pylint`] Fix `PLW0108` autofix introducing a syntax error when the lambda's body contains an assignment expression (#18678) 2025-06-26 16:56:17 -04:00
unnecessary_list_index_lookup.py [`pylint`] Recurse into subscript subexpressions when searching for list/dict lookups (`PLR1733`, `PLR1736`) (#13186) 2024-09-01 17:22:45 +01:00
unreachable.py Control flow: `return` and `raise` (#17121) 2025-04-03 08:30:29 -05:00
unspecified_encoding.py [`pylint`] Detect indirect `pathlib.Path` usages for `unspecified-encoding` (PLW1514) (#19304) 2025-07-16 12:57:31 -04:00
useless_else_on_loop.py [`pylint`] Add fix for `useless-else-on-loop` (`PLW0120`) (#9590) 2024-01-21 11:17:58 -05:00
useless_exception_statement.py [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382) 2025-12-09 13:49:55 -05:00
useless_return.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
useless_with_lock.py [pylint] Implement `useless-with-lock` (#8321) 2023-10-29 16:24:52 +00:00
yield_from_in_async_function.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00
yield_in_init.py Rename `ruff` crate to `ruff_linter` (#7529) 2023-09-20 08:38:27 +02:00