[flake8-pyi] Remove type parameter correctly when it is the last (PYI019) (#15854)

This commit is contained in:
InSync 2025-01-31 23:22:54 +07:00 committed by GitHub
parent ce769f6ae2
commit b2cb757fa8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 1 deletions

View file

@ -112,3 +112,7 @@ def shadowed_type():
class SubscriptReturnType: class SubscriptReturnType:
@classmethod @classmethod
def m[S](cls: type[S]) -> type[S]: ... # PYI019, but no autofix (yet) def m[S](cls: type[S]) -> type[S]: ... # PYI019, but no autofix (yet)
class PEP695TypeParameterAtTheVeryEndOfTheList:
def f[T, S](self: S) -> S: ...

View file

@ -430,7 +430,7 @@ fn remove_typevar_declaration(type_params: Option<&TypeParams>, name: &str) -> O
// [A, B, C] // [A, B, C]
// ^^^ Remove this // ^^^ Remove this
let previous_range = parameters[index - 1].range(); 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)) Some(Edit::range_deletion(range))

View file

@ -224,3 +224,11 @@ PYI019.pyi:114:31: PYI019 Methods like `m` should return `Self` instead of a cus
| ^^^^^^^ PYI019 | ^^^^^^^ PYI019
| |
= help: Replace with `Self` = 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`

View file

@ -444,3 +444,18 @@ PYI019.pyi:114:31: PYI019 Methods like `m` should return `Self` instead of a cus
| ^^^^^^^ PYI019 | ^^^^^^^ PYI019
| |
= help: Replace with `Self` = 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: ...