Skip to content

Commit

Permalink
feat: enable autofix for TRY004 (#2084)
Browse files Browse the repository at this point in the history
functionality was already implemented, just the trait needed to be added
  • Loading branch information
sbrugman committed Jan 22, 2023
1 parent c1cb479 commit 6fc6bf0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/rules/tryceratops/rules/prefer_type_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6fc6bf0

Please sign in to comment.