ty
ty copied to clipboard
Server: renaming a property getter should also cause the setter and deleter to be renamed (if they're present)
Summary
For this class:
class Foo:
@property
def bar(self) -> str:
return "baz"
@bar.setter
def bar(self, value: str) -> None:
pass
@bar.deleter
def bar(self) -> None:
pass
If you have Pylance disabled in VSCode and the ty-vscode extension installed, right-clicking on the first bar function and renaming it to spam will apply this diff to your code:
class Foo:
@property
- def bar(self) -> str:
+ def spam(self) -> str:
return "baz"
- @bar.setter
+ @spam.setter
def bar(self, value: str) -> None:
pass
- @bar.deleter
+ @spam.deleter
def bar(self) -> None:
pass
But if you enable Pylance and do the rename, then this edit is applied instead from the same operation:
class Foo:
@property
- def bar(self) -> str:
+ def spam(self) -> str:
return "baz"
- @bar.setter
- def bar(self, value: str) -> None:
+ @spam.setter
+ def spam(self, value: str) -> None:
pass
- @bar.deleter
- def bar(self) -> None:
+ @spam.deleter
+ def spam(self) -> None:
pass
The Pylance behaviour is how I would want a property rename to work; the ty behaviour should match that.
Failing tests for this were added in https://github.com/astral-sh/ruff/pull/21810; a fix for this issue should aim to resolve the TODOs added in that PR.
Version
No response