diff --git a/python/src/com/jetbrains/python/codeInsight/PyTypingTypeProvider.java b/python/src/com/jetbrains/python/codeInsight/PyTypingTypeProvider.java index 7c2a51ebb0ce..8d267245eb8f 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyTypingTypeProvider.java +++ b/python/src/com/jetbrains/python/codeInsight/PyTypingTypeProvider.java @@ -97,7 +97,7 @@ public class PyTypingTypeProvider extends PyTypeProviderBase { final List paramTypes = functionType.getParameters(context); assert paramTypes != null; final PyParameter[] funcParams = func.getParameterList().getParameters(); - final int startOffset = func.getContainingClass() != null ? 1 : 0; + final int startOffset = omitFirstParamInTypeComment(func) ? 1 : 0; for (int paramIndex = 0; paramIndex < funcParams.length; paramIndex++) { if (funcParams[paramIndex] == param) { final int typeIndex = paramIndex - startOffset; @@ -112,6 +112,10 @@ public class PyTypingTypeProvider extends PyTypeProviderBase { return null; } + private static boolean omitFirstParamInTypeComment(@NotNull PyFunction func) { + return func.getContainingClass() != null && func.getModifier() != PyFunction.Modifier.STATICMETHOD; + } + @Nullable @Override public Ref getReturnType(@NotNull PyCallable callable, @NotNull TypeEvalContext context) { diff --git a/python/testSrc/com/jetbrains/python/PyTypingTest.java b/python/testSrc/com/jetbrains/python/PyTypingTest.java index c49b8eb89b80..8659fd088d1a 100644 --- a/python/testSrc/com/jetbrains/python/PyTypingTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypingTest.java @@ -461,6 +461,17 @@ public class PyTypingTest extends PyTestCase { "expr = f"); } + // PY-18595 + public void testFunctionTypeCommentForStaticMethod() { + doTest("int", + "class C:\n" + + " @staticmethod\n" + + " def m(some_int, some_bool, some_str):\n" + + " # type: (int, bool, str) -> bool\n" + + " expr = some_int"); + + } + private void doTestNoInjectedText(@NotNull String text) { myFixture.configureByText(PythonFileType.INSTANCE, text); final InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(myFixture.getProject());