Skip to content

Commit

Permalink
[flake8-pyi] Remove type parameter correctly when it is the last (`…
Browse files Browse the repository at this point in the history
…PYI019`) (astral-sh#15854)
  • Loading branch information
InSyncWithFoo authored Jan 31, 2025
1 parent ce769f6 commit b2cb757
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

0 comments on commit b2cb757

Please sign in to comment.