From 6fc6bf06489e7c9cfde17e56ceace0531c6c656e Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Sun, 22 Jan 2023 13:18:56 +0100 Subject: [PATCH] feat: enable autofix for TRY004 (#2084) functionality was already implemented, just the trait needed to be added --- README.md | 2 +- src/rules/tryceratops/rules/prefer_type_error.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5f8d90a7fd..28f7ca0c45 100644 --- a/README.md +++ b/README.md @@ -1194,7 +1194,7 @@ For more, see [tryceratops](https://pypi.org/project/tryceratops/1.1.0/) on PyPI | Code | Name | Message | Fix | | ---- | ---- | ------- | --- | -| TRY004 | prefer-type-error | Prefer `TypeError` exception for invalid type | | +| TRY004 | prefer-type-error | Prefer `TypeError` exception for invalid type | 🛠 | | TRY300 | try-consider-else | Consider `else` block | | ### Ruff-specific rules (RUF) diff --git a/src/rules/tryceratops/rules/prefer_type_error.rs b/src/rules/tryceratops/rules/prefer_type_error.rs index 5d406aa009..6bde060af9 100644 --- a/src/rules/tryceratops/rules/prefer_type_error.rs +++ b/src/rules/tryceratops/rules/prefer_type_error.rs @@ -6,16 +6,20 @@ use crate::checkers::ast::Checker; use crate::define_violation; use crate::fix::Fix; use crate::registry::Diagnostic; -use crate::violation::Violation; +use crate::violation::AlwaysAutofixableViolation; define_violation!( pub struct PreferTypeError; ); -impl Violation for PreferTypeError { +impl AlwaysAutofixableViolation for PreferTypeError { #[derive_message_formats] fn message(&self) -> String { format!("Prefer `TypeError` exception for invalid type") } + + fn autofix_title(&self) -> String { + "Use `TypeError` exception type".to_string() + } } /// Returns `true` if an [`Expr`] is a call to check types.