mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Provide generic type for self or cls
As a result, class-wide type variables will not be substituted inside methods. GitOrigin-RevId: 8f341042f4944f61e212cf226b4736e9eb26ba8d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
28dfeb83f5
commit
d79f13cf5a
@@ -236,6 +236,14 @@ public class PyNamedParameterImpl extends PyBaseElementImpl<PyNamedParameterStub
|
||||
final PyClass containingClass = func.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
final PyFunction.Modifier modifier = func.getModifier();
|
||||
|
||||
final PyType genericType = new PyTypingTypeProvider().getGenericType(containingClass, context);
|
||||
if (genericType != null) {
|
||||
return modifier == PyFunction.Modifier.CLASSMETHOD && genericType instanceof PyInstantiableType
|
||||
? ((PyInstantiableType<?>)genericType).toClass()
|
||||
: genericType;
|
||||
}
|
||||
|
||||
return new PyClassTypeImpl(containingClass, modifier == PyFunction.Modifier.CLASSMETHOD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
print(dict.fromkeys(<warning descr="Parameter(s) unfilledPossible callees:dict.fromkeys(cls: Type[dict], __iterable: Iterable[_T])dict.fromkeys(cls: Type[dict], __iterable: Iterable[_T], __value: _S)">)</warning>)
|
||||
print(dict.fromkeys(<warning descr="Parameter(s) unfilledPossible callees:dict.fromkeys(cls: Type[Dict[_KT, _VT]], __iterable: Iterable[_T])dict.fromkeys(cls: Type[Dict[_KT, _VT]], __iterable: Iterable[_T], __value: _S)">)</warning>)
|
||||
print(dict.fromkeys(['foo', 'bar']))
|
||||
|
||||
@@ -1092,7 +1092,7 @@ public class Py3TypeTest extends PyTestCase {
|
||||
// PY-27783
|
||||
public void testApplyingSuperSubstitutionToGenericClass() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.PYTHON36,
|
||||
LanguageLevel.getLatest(),
|
||||
() -> doTest("Dict[T, int]",
|
||||
"from typing import TypeVar, Generic, Dict, List\n" +
|
||||
"\n" +
|
||||
@@ -1110,6 +1110,27 @@ public class Py3TypeTest extends PyTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
// PY-27783
|
||||
public void testApplyingSuperSubstitutionToBoundedGenericClass() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.getLatest(),
|
||||
() -> doTest("Dict[T, int]",
|
||||
"from typing import TypeVar, Generic, Dict, List\n" +
|
||||
"\n" +
|
||||
"T = TypeVar('T', bound=str)\n" +
|
||||
"\n" +
|
||||
"class A(Generic[T]):\n" +
|
||||
" pass\n" +
|
||||
"\n" +
|
||||
"class B(A[List[T]], Generic[T]):\n" +
|
||||
" def __init__(self) -> None:\n" +
|
||||
" self.value_set: Dict[T, int] = {}\n" +
|
||||
"\n" +
|
||||
" def foo(self) -> None:\n" +
|
||||
" expr = self.value_set")
|
||||
);
|
||||
}
|
||||
|
||||
// PY-13750
|
||||
public void testBuiltinRound() {
|
||||
doTest("int", "expr = round(1)");
|
||||
|
||||
Reference in New Issue
Block a user