mirror of https://github.com/astral-sh/ruff
feat: enable autofix for TRY004 (#2084)
functionality was already implemented, just the trait needed to be added
This commit is contained in:
parent
c1cb4796f8
commit
6fc6bf0648
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue