From 50f900252ce8df3e96db5c11bf3ec33bded1ed26 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Thu, 8 Nov 2018 14:23:59 +0300 Subject: [PATCH] Check that modifier wrapping call is for function which modifier is calculating (PY-30182) --- .../src/com/jetbrains/python/psi/impl/PyFunctionImpl.java | 3 ++- .../AnotherMethodIsWrappedIntoStatic/a.py | 3 +++ .../AnotherMethodIsWrappedIntoStatic/b.py | 8 ++++++++ .../python/inspections/PyArgumentListInspectionTest.java | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 python/testData/inspections/PyArgumentListInspection/AnotherMethodIsWrappedIntoStatic/a.py create mode 100644 python/testData/inspections/PyArgumentListInspection/AnotherMethodIsWrappedIntoStatic/b.py diff --git a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java index e6884c84d402..0f24a0e69837 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java @@ -811,7 +811,8 @@ public class PyFunctionImpl extends PyBaseElementImpl implements .skipWhile(siblingStub -> !stub.equals(siblingStub)) .transform(nextSiblingStub -> as(nextSiblingStub, PyTargetExpressionStub.class)) .filter(Objects::nonNull) - .filter(nextSiblingStub -> nextSiblingStub.getInitializerType() == PyTargetExpressionStub.InitializerType.CallExpression) + .filter(nextSiblingStub -> nextSiblingStub.getInitializerType() == PyTargetExpressionStub.InitializerType.CallExpression && + Objects.equals(stub.getName(), nextSiblingStub.getName())) .transform(PyTargetExpressionStub::getInitializer) .transform( initializerName -> { diff --git a/python/testData/inspections/PyArgumentListInspection/AnotherMethodIsWrappedIntoStatic/a.py b/python/testData/inspections/PyArgumentListInspection/AnotherMethodIsWrappedIntoStatic/a.py new file mode 100644 index 000000000000..3bed35c16015 --- /dev/null +++ b/python/testData/inspections/PyArgumentListInspection/AnotherMethodIsWrappedIntoStatic/a.py @@ -0,0 +1,3 @@ +from b import A + +A().my_method(10) \ No newline at end of file diff --git a/python/testData/inspections/PyArgumentListInspection/AnotherMethodIsWrappedIntoStatic/b.py b/python/testData/inspections/PyArgumentListInspection/AnotherMethodIsWrappedIntoStatic/b.py new file mode 100644 index 000000000000..4f6dad712c51 --- /dev/null +++ b/python/testData/inspections/PyArgumentListInspection/AnotherMethodIsWrappedIntoStatic/b.py @@ -0,0 +1,8 @@ +class A: + def my_method(self, p): + pass + + def one_more(p): + pass + + one_more = staticmethod(one_more) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java index eaa229b5ef14..2ba9a853e628 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java @@ -366,4 +366,9 @@ public class PyArgumentListInspectionTest extends PyInspectionTestCase { public void testInitializingTypeVar() { doTest(); } + + // PY-30182 + public void testAnotherMethodIsWrappedIntoStatic() { + doMultiFileTest(); + } }