From d79f13cf5a1112bb79a61f4822acc12abf03fc6e Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Thu, 18 Jun 2020 00:13:44 +0300 Subject: [PATCH] Provide generic type for `self` or `cls` As a result, class-wide type variables will not be substituted inside methods. GitOrigin-RevId: 8f341042f4944f61e212cf226b4736e9eb26ba8d --- .../python/psi/impl/PyNamedParameterImpl.java | 8 +++++++ .../PyArgumentListInspection/dictFromKeys.py | 2 +- .../com/jetbrains/python/Py3TypeTest.java | 23 ++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/python/python-psi-impl/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java b/python/python-psi-impl/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java index a194d5e74ebe..7cce6c0089fd 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java +++ b/python/python-psi-impl/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java @@ -236,6 +236,14 @@ public class PyNamedParameterImpl extends PyBaseElementImpl)genericType).toClass() + : genericType; + } + return new PyClassTypeImpl(containingClass, modifier == PyFunction.Modifier.CLASSMETHOD); } } diff --git a/python/testData/inspections/PyArgumentListInspection/dictFromKeys.py b/python/testData/inspections/PyArgumentListInspection/dictFromKeys.py index d9a9776a5b52..fb2a7d6f1186 100644 --- a/python/testData/inspections/PyArgumentListInspection/dictFromKeys.py +++ b/python/testData/inspections/PyArgumentListInspection/dictFromKeys.py @@ -1,2 +1,2 @@ -print(dict.fromkeys()) +print(dict.fromkeys()) print(dict.fromkeys(['foo', 'bar'])) diff --git a/python/testSrc/com/jetbrains/python/Py3TypeTest.java b/python/testSrc/com/jetbrains/python/Py3TypeTest.java index fce2d7de7a9e..5a35aa47c2bc 100644 --- a/python/testSrc/com/jetbrains/python/Py3TypeTest.java +++ b/python/testSrc/com/jetbrains/python/Py3TypeTest.java @@ -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)");