PY-11858 Fix rename functon parameter along with decorator argument

If docorated function has a parameter and the decorator has
an argument with the same name as the parameter then we must not rename
the argument in case of renaming the parameter.

GitOrigin-RevId: ebc5dcf7448080e2762004a2779cd06700c042a8
This commit is contained in:
Mikhail Khorkov
2020-09-16 12:26:09 +00:00
committed by intellij-monorepo-bot
parent 941cdc466b
commit a7668df48f
4 changed files with 49 additions and 1 deletions
@@ -561,7 +561,7 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
final PsiElement ourContainer = findContainer(getElement());
final PsiElement theirContainer = findContainer(element);
if (ourContainer != null) {
if (ourContainer == theirContainer) {
if (ourContainer == theirContainer && ourScopeOwner == theirScopeOwner) {
return true;
}
if (PsiTreeUtil.isAncestor(theirContainer, ourContainer, true)) {
@@ -0,0 +1,22 @@
from functools import wraps
def d(x):
def dec(f):
@wraps(f)
def wrapper(*args, **kwargs):
print(f'x = {x}')
return f(*args, **kwargs)
return wrapper
return dec
class C:
foo = 0
@d(foo) # 2. This is renamed either but it shouldn't
def f(self, <caret>foo): # 1. Rename this 'foo' to 'bar'
print(foo)
C().f(1)
@@ -0,0 +1,22 @@
from functools import wraps
def d(x):
def dec(f):
@wraps(f)
def wrapper(*args, **kwargs):
print(f'x = {x}')
return f(*args, **kwargs)
return wrapper
return dec
class C:
foo = 0
@d(foo) # 2. This is renamed either but it shouldn't
def f(self, bar): # 1. Rename this 'foo' to 'bar'
print(bar)
C().f(1)
@@ -43,6 +43,10 @@ public class PyRenameTest extends PyTestCase {
doTest("qu");
}
public void testRenameParameterWithDecorator() { // PY-11858
doTest("bar");
}
public void testRenameMultipleDefinitionsLocal() { // PY-727
doTest("qu");
}