Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::checkers::ast::Checker;
use crate::fix::edits::{Parentheses, remove_argument};
use crate::{Fix, FixAvailability, Violation};
use ruff_diagnostics::Applicability;
use ruff_macros::{ViolationMetadata, derive_message_formats};
use ruff_python_ast::StmtClassDef;
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -63,13 +64,21 @@ pub(crate) fn useless_class_metaclass_type(checker: &Checker, class_def: &StmtCl
);

diagnostic.try_set_fix(|| {
remove_argument(
let edit = remove_argument(
keyword,
arguments,
Parentheses::Remove,
checker.locator().contents(),
)
.map(Fix::safe_edit)
)?;

let range = edit.range();
let applicability = if checker.comment_ranges().intersects(range) {
Applicability::Unsafe
} else {
Applicability::Safe
};

Ok(Fix::applicable_edit(edit, applicability))
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ UP050.py:16:5: UP050 [*] Class `A` uses `metaclass=type`, which is redundant
|
= help: Remove `metaclass=type`

Safe fix
Unsafe fix
12 12 | ...
13 13 |
14 14 |
Expand All @@ -75,7 +75,7 @@ UP050.py:24:5: UP050 [*] Class `A` uses `metaclass=type`, which is redundant
|
= help: Remove `metaclass=type`

Safe fix
Unsafe fix
19 19 | ...
20 20 |
21 21 |
Expand All @@ -98,7 +98,7 @@ UP050.py:30:5: UP050 [*] Class `A` uses `metaclass=type`, which is redundant
|
= help: Remove `metaclass=type`

Safe fix
Unsafe fix
26 26 | ...
27 27 |
28 28 |
Expand All @@ -122,7 +122,7 @@ UP050.py:38:5: UP050 [*] Class `A` uses `metaclass=type`, which is redundant
|
= help: Remove `metaclass=type`

Safe fix
Unsafe fix
33 33 | ...
34 34 |
35 35 |
Expand Down Expand Up @@ -185,7 +185,7 @@ UP050.py:58:5: UP050 [*] Class `B` uses `metaclass=type`, which is redundant
|
= help: Remove `metaclass=type`

Safe fix
Unsafe fix
54 54 |
55 55 | class B(
56 56 | A,
Expand All @@ -205,7 +205,7 @@ UP050.py:69:5: UP050 [*] Class `A` uses `metaclass=type`, which is redundant
|
= help: Remove `metaclass=type`

Safe fix
Unsafe fix
65 65 | ...
66 66 |
67 67 |
Expand Down