diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI019.pyi b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI019.pyi index 7a2ad05a7350d..ae58a2d147ff1 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI019.pyi +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI019.pyi @@ -112,3 +112,7 @@ def shadowed_type(): class SubscriptReturnType: @classmethod def m[S](cls: type[S]) -> type[S]: ... # PYI019, but no autofix (yet) + + +class PEP695TypeParameterAtTheVeryEndOfTheList: + def f[T, S](self: S) -> S: ... diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs index 2a98b52ff663a..f30a9d72b7ef0 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_return_type.rs @@ -430,7 +430,7 @@ fn remove_typevar_declaration(type_params: Option<&TypeParams>, name: &str) -> O // [A, B, C] // ^^^ Remove this let previous_range = parameters[index - 1].range(); - TextRange::new(previous_range.end(), typevar_range.start()) + TextRange::new(previous_range.end(), typevar_range.end()) }; Some(Edit::range_deletion(range)) diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI019_PYI019.pyi.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI019_PYI019.pyi.snap index 8103ddd5a1a30..af1d9d3e7251b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI019_PYI019.pyi.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI019_PYI019.pyi.snap @@ -224,3 +224,11 @@ PYI019.pyi:114:31: PYI019 Methods like `m` should return `Self` instead of a cus | ^^^^^^^ PYI019 | = help: Replace with `Self` + +PYI019.pyi:118:29: PYI019 Methods like `f` should return `Self` instead of a custom `TypeVar` + | +117 | class PEP695TypeParameterAtTheVeryEndOfTheList: +118 | def f[T, S](self: S) -> S: ... + | ^ PYI019 + | + = help: Replace with `Self` diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__custom_classmethod_rules_preview.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__custom_classmethod_rules_preview.snap index 7c1b0073b311d..8a3913ab8dd5f 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__custom_classmethod_rules_preview.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__custom_classmethod_rules_preview.snap @@ -444,3 +444,18 @@ PYI019.pyi:114:31: PYI019 Methods like `m` should return `Self` instead of a cus | ^^^^^^^ PYI019 | = help: Replace with `Self` + +PYI019.pyi:118:29: PYI019 [*] Methods like `f` should return `Self` instead of a custom `TypeVar` + | +117 | class PEP695TypeParameterAtTheVeryEndOfTheList: +118 | def f[T, S](self: S) -> S: ... + | ^ PYI019 + | + = help: Replace with `Self` + +ℹ Safe fix +115 115 | +116 116 | +117 117 | class PEP695TypeParameterAtTheVeryEndOfTheList: +118 |- def f[T, S](self: S) -> S: ... + 118 |+ def f[T](self) -> Self: ...