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
2 changes: 0 additions & 2 deletions crates/ruff_linter/src/rules/flake8_pyi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ mod tests {
}

#[test_case(Rule::FutureAnnotationsInStub, Path::new("PYI044.pyi"))]
#[test_case(Rule::UnusedPrivateTypeVar, Path::new("PYI018.py"))]
#[test_case(Rule::UnusedPrivateTypeVar, Path::new("PYI018.pyi"))]
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!(
"preview__{}_{}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ use crate::fix;
/// _Ts = typing_extensions.TypeVarTuple("_Ts")
/// ```
///
/// ## Fix safety and availability
/// This rule's fix is available when [`preview`] mode is enabled.
/// It is always marked as unsafe, as it would break your code if the type
/// ## Fix safety
/// The fix is always marked as unsafe, as it would break your code if the type
/// variable is imported by another module.
#[derive(ViolationMetadata)]
pub(crate) struct UnusedPrivateTypeVar {
Expand Down Expand Up @@ -225,18 +224,19 @@ pub(crate) fn unused_private_type_var(checker: &Checker, scope: &Scope) {
continue;
};

let mut diagnostic = Diagnostic::new(
let diagnostic = Diagnostic::new(
UnusedPrivateTypeVar {
type_var_like_name: id.to_string(),
type_var_like_kind: type_var_like_kind.to_string(),
},
binding.range(),
);

if checker.settings.preview.is_enabled() {
let edit = fix::edits::delete_stmt(stmt, None, checker.locator(), checker.indexer());
diagnostic.set_fix(Fix::unsafe_edit(edit));
}
)
.with_fix(Fix::unsafe_edit(fix::edits::delete_stmt(
stmt,
None,
checker.locator(),
checker.indexer(),
)));

checker.report_diagnostic(diagnostic);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
---
PYI018.py:6:1: PYI018 Private TypeVar `_T` is never used
PYI018.py:6:1: PYI018 [*] Private TypeVar `_T` is never used
|
4 | from typing_extensions import ParamSpec, TypeVarTuple
5 |
Expand All @@ -12,7 +12,16 @@ PYI018.py:6:1: PYI018 Private TypeVar `_T` is never used
|
= help: Remove unused private TypeVar `_T`

PYI018.py:7:1: PYI018 Private TypeVarTuple `_Ts` is never used
ℹ Unsafe fix
3 3 | from typing import TypeVar
4 4 | from typing_extensions import ParamSpec, TypeVarTuple
5 5 |
6 |-_T = typing.TypeVar("_T")
7 6 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 7 | _P = ParamSpec("_P")
9 8 | _P2 = typing.ParamSpec("_P2")

PYI018.py:7:1: PYI018 [*] Private TypeVarTuple `_Ts` is never used
|
6 | _T = typing.TypeVar("_T")
7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
Expand All @@ -22,7 +31,16 @@ PYI018.py:7:1: PYI018 Private TypeVarTuple `_Ts` is never used
|
= help: Remove unused private TypeVarTuple `_Ts`

PYI018.py:8:1: PYI018 Private ParamSpec `_P` is never used
ℹ Unsafe fix
4 4 | from typing_extensions import ParamSpec, TypeVarTuple
5 5 |
6 6 | _T = typing.TypeVar("_T")
7 |-_Ts = typing_extensions.TypeVarTuple("_Ts")
8 7 | _P = ParamSpec("_P")
9 8 | _P2 = typing.ParamSpec("_P2")
10 9 | _Ts2 = TypeVarTuple("_Ts2")

PYI018.py:8:1: PYI018 [*] Private ParamSpec `_P` is never used
|
6 | _T = typing.TypeVar("_T")
7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
Expand All @@ -33,7 +51,16 @@ PYI018.py:8:1: PYI018 Private ParamSpec `_P` is never used
|
= help: Remove unused private ParamSpec `_P`

PYI018.py:9:1: PYI018 Private ParamSpec `_P2` is never used
ℹ Unsafe fix
5 5 |
6 6 | _T = typing.TypeVar("_T")
7 7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 |-_P = ParamSpec("_P")
9 8 | _P2 = typing.ParamSpec("_P2")
10 9 | _Ts2 = TypeVarTuple("_Ts2")
11 10 |

PYI018.py:9:1: PYI018 [*] Private ParamSpec `_P2` is never used
|
7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 | _P = ParamSpec("_P")
Expand All @@ -43,7 +70,16 @@ PYI018.py:9:1: PYI018 Private ParamSpec `_P2` is never used
|
= help: Remove unused private ParamSpec `_P2`

PYI018.py:10:1: PYI018 Private TypeVarTuple `_Ts2` is never used
ℹ Unsafe fix
6 6 | _T = typing.TypeVar("_T")
7 7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 8 | _P = ParamSpec("_P")
9 |-_P2 = typing.ParamSpec("_P2")
10 9 | _Ts2 = TypeVarTuple("_Ts2")
11 10 |
12 11 | # OK

PYI018.py:10:1: PYI018 [*] Private TypeVarTuple `_Ts2` is never used
|
8 | _P = ParamSpec("_P")
9 | _P2 = typing.ParamSpec("_P2")
Expand All @@ -53,3 +89,12 @@ PYI018.py:10:1: PYI018 Private TypeVarTuple `_Ts2` is never used
12 | # OK
|
= help: Remove unused private TypeVarTuple `_Ts2`

ℹ Unsafe fix
7 7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 8 | _P = ParamSpec("_P")
9 9 | _P2 = typing.ParamSpec("_P2")
10 |-_Ts2 = TypeVarTuple("_Ts2")
11 10 |
12 11 | # OK
13 12 | _UsedTypeVar = TypeVar("_UsedTypeVar")
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
---
PYI018.pyi:6:1: PYI018 Private TypeVar `_T` is never used
PYI018.pyi:6:1: PYI018 [*] Private TypeVar `_T` is never used
|
4 | from typing_extensions import ParamSpec, TypeVarTuple
5 |
Expand All @@ -12,7 +12,16 @@ PYI018.pyi:6:1: PYI018 Private TypeVar `_T` is never used
|
= help: Remove unused private TypeVar `_T`

PYI018.pyi:7:1: PYI018 Private TypeVarTuple `_Ts` is never used
ℹ Unsafe fix
3 3 | from typing import TypeVar
4 4 | from typing_extensions import ParamSpec, TypeVarTuple
5 5 |
6 |-_T = typing.TypeVar("_T")
7 6 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 7 | _P = ParamSpec("_P")
9 8 | _P2 = typing.ParamSpec("_P2")

PYI018.pyi:7:1: PYI018 [*] Private TypeVarTuple `_Ts` is never used
|
6 | _T = typing.TypeVar("_T")
7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
Expand All @@ -22,7 +31,16 @@ PYI018.pyi:7:1: PYI018 Private TypeVarTuple `_Ts` is never used
|
= help: Remove unused private TypeVarTuple `_Ts`

PYI018.pyi:8:1: PYI018 Private ParamSpec `_P` is never used
ℹ Unsafe fix
4 4 | from typing_extensions import ParamSpec, TypeVarTuple
5 5 |
6 6 | _T = typing.TypeVar("_T")
7 |-_Ts = typing_extensions.TypeVarTuple("_Ts")
8 7 | _P = ParamSpec("_P")
9 8 | _P2 = typing.ParamSpec("_P2")
10 9 | _Ts2 = TypeVarTuple("_Ts2")

PYI018.pyi:8:1: PYI018 [*] Private ParamSpec `_P` is never used
|
6 | _T = typing.TypeVar("_T")
7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
Expand All @@ -33,7 +51,16 @@ PYI018.pyi:8:1: PYI018 Private ParamSpec `_P` is never used
|
= help: Remove unused private ParamSpec `_P`

PYI018.pyi:9:1: PYI018 Private ParamSpec `_P2` is never used
ℹ Unsafe fix
5 5 |
6 6 | _T = typing.TypeVar("_T")
7 7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 |-_P = ParamSpec("_P")
9 8 | _P2 = typing.ParamSpec("_P2")
10 9 | _Ts2 = TypeVarTuple("_Ts2")
11 10 |

PYI018.pyi:9:1: PYI018 [*] Private ParamSpec `_P2` is never used
|
7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 | _P = ParamSpec("_P")
Expand All @@ -43,7 +70,16 @@ PYI018.pyi:9:1: PYI018 Private ParamSpec `_P2` is never used
|
= help: Remove unused private ParamSpec `_P2`

PYI018.pyi:10:1: PYI018 Private TypeVarTuple `_Ts2` is never used
ℹ Unsafe fix
6 6 | _T = typing.TypeVar("_T")
7 7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 8 | _P = ParamSpec("_P")
9 |-_P2 = typing.ParamSpec("_P2")
10 9 | _Ts2 = TypeVarTuple("_Ts2")
11 10 |
12 11 | # OK

PYI018.pyi:10:1: PYI018 [*] Private TypeVarTuple `_Ts2` is never used
|
8 | _P = ParamSpec("_P")
9 | _P2 = typing.ParamSpec("_P2")
Expand All @@ -53,3 +89,12 @@ PYI018.pyi:10:1: PYI018 Private TypeVarTuple `_Ts2` is never used
12 | # OK
|
= help: Remove unused private TypeVarTuple `_Ts2`

ℹ Unsafe fix
7 7 | _Ts = typing_extensions.TypeVarTuple("_Ts")
8 8 | _P = ParamSpec("_P")
9 9 | _P2 = typing.ParamSpec("_P2")
10 |-_Ts2 = TypeVarTuple("_Ts2")
11 10 |
12 11 | # OK
13 12 | _UsedTypeVar = TypeVar("_UsedTypeVar")

This file was deleted.

Loading
Loading