mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Also drop cls-parameter for qualified reference that resolves to method (PY-26616)
This commit is contained in:
@@ -369,9 +369,9 @@ public class PyCallExpressionHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isQualifiedByInstance(@Nullable PyCallable resolved,
|
||||
@NotNull PyExpression qualifier,
|
||||
@NotNull TypeEvalContext context) {
|
||||
private static boolean isQualifiedByInstance(@Nullable PyCallable resolved,
|
||||
@NotNull PyExpression qualifier,
|
||||
@NotNull TypeEvalContext context) {
|
||||
if (isQualifiedByClass(resolved, qualifier, context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
private static PyType getTypeFromTarget(@NotNull PsiElement target,
|
||||
@NotNull TypeEvalContext context,
|
||||
@NotNull PyReferenceExpression anchor) {
|
||||
final PyType type = dropSelfForInstanceMethod(getGenericTypeFromTarget(target, context, anchor), context, anchor);
|
||||
final PyType type = dropSelfForQualifiedMethod(getGenericTypeFromTarget(target, context, anchor), context, anchor);
|
||||
|
||||
if (context.maySwitchToAST(anchor)) {
|
||||
final PyExpression qualifier = anchor.getQualifier();
|
||||
@@ -501,16 +501,11 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PyType dropSelfForInstanceMethod(@Nullable PyType type,
|
||||
@NotNull TypeEvalContext context,
|
||||
@NotNull PyReferenceExpression anchor) {
|
||||
if (type instanceof PyFunctionType && context.maySwitchToAST(anchor)) {
|
||||
final PyExpression qualifier = anchor.getQualifier();
|
||||
final PyFunctionType functionType = (PyFunctionType)type;
|
||||
|
||||
if (qualifier != null && PyCallExpressionHelper.isQualifiedByInstance(functionType.getCallable(), qualifier, context)) {
|
||||
return functionType.dropSelf(context);
|
||||
}
|
||||
private static PyType dropSelfForQualifiedMethod(@Nullable PyType type,
|
||||
@NotNull TypeEvalContext context,
|
||||
@NotNull PyReferenceExpression anchor) {
|
||||
if (type instanceof PyFunctionType && context.maySwitchToAST(anchor) && anchor.getQualifier() != null) {
|
||||
return ((PyFunctionType)type).dropSelf(context);
|
||||
}
|
||||
|
||||
return type;
|
||||
|
||||
@@ -1947,6 +1947,16 @@ public class PyTypeTest extends PyTestCase {
|
||||
"expr = my_list.count");
|
||||
}
|
||||
|
||||
// PY-26616
|
||||
public void testClassMethodQualifiedWithDefinition() {
|
||||
doTest("(x: str) -> Foo",
|
||||
"class Foo:\n" +
|
||||
" @classmethod\n" +
|
||||
" def make_foo(cls, x: str) -> 'Foo':\n" +
|
||||
" pass\n" +
|
||||
"expr = Foo.make_foo");
|
||||
}
|
||||
|
||||
public void testConstructingGenericClassWithNotFilledGenericValue() {
|
||||
doTest("MyIterator",
|
||||
"from typing import Iterator\n" +
|
||||
|
||||
Reference in New Issue
Block a user