diff --git a/python/python-psi-impl/src/com/jetbrains/python/psi/impl/references/PyReferenceImpl.java b/python/python-psi-impl/src/com/jetbrains/python/psi/impl/references/PyReferenceImpl.java index 8011fbdeee16..3d55548ff32d 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/psi/impl/references/PyReferenceImpl.java +++ b/python/python-psi-impl/src/com/jetbrains/python/psi/impl/references/PyReferenceImpl.java @@ -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)) { diff --git a/python/testData/refactoring/rename/renameParameterWithDecorator.py b/python/testData/refactoring/rename/renameParameterWithDecorator.py new file mode 100644 index 000000000000..ce00c3238c8d --- /dev/null +++ b/python/testData/refactoring/rename/renameParameterWithDecorator.py @@ -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, foo): # 1. Rename this 'foo' to 'bar' + print(foo) + + +C().f(1) \ No newline at end of file diff --git a/python/testData/refactoring/rename/renameParameterWithDecorator_after.py b/python/testData/refactoring/rename/renameParameterWithDecorator_after.py new file mode 100644 index 000000000000..2281bc46349d --- /dev/null +++ b/python/testData/refactoring/rename/renameParameterWithDecorator_after.py @@ -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) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java index ed476a3a8fa6..63a6b7094992 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java @@ -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"); }