mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
PY-18595 Use annotation from type comment for the first parameter of static methods
This commit is contained in:
@@ -97,7 +97,7 @@ public class PyTypingTypeProvider extends PyTypeProviderBase {
|
||||
final List<PyCallableParameter> 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<PyType> getReturnType(@NotNull PyCallable callable, @NotNull TypeEvalContext context) {
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user