PY-78250 Call PyDataclassTypeProvider before PyTypingTypeProvider so that it has a chance to infer the dataclass type first

GitOrigin-RevId: 18230af949275e3f585ce806fec25144731e347b
This commit is contained in:
evgeny.bovykin
2025-03-20 09:52:43 +01:00
committed by intellij-monorepo-bot
parent cabd6ccecc
commit 93efb0ac16
7 changed files with 78 additions and 2 deletions

View File

@@ -530,7 +530,7 @@
<customDecoratorStubType implementation="com.jetbrains.python.psi.stubs.PyDataclassTransformDecoratorStubType"/>
<!-- typing -->
<typeProvider implementation="com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider"/>
<typeProvider id="pyTypingTypeProvider" implementation="com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider" order="before pythonDocstringTypeProvider"/>
<typeProvider implementation="com.jetbrains.python.pyi.PyiTypeProvider"/>
<typeProvider implementation="com.jetbrains.python.codeInsight.typing.PyTypedDictTypeProvider"/>
<typeProvider implementation="com.jetbrains.python.codeInsight.typing.PyTypingNewTypeTypeProvider"/>
@@ -571,7 +571,9 @@
<!--stdlib-->
<canonicalPathProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyStdlibCanonicalPathProvider"/>
<inspectionExtension implementation="com.jetbrains.python.inspections.stdlib.PyStdlibInspectionExtension"/>
<typeProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyDataclassTypeProvider"/>
<typeProvider implementation="com.jetbrains.python.codeInsight.stdlib.PyDataclassTypeProvider"
order="before pyTypingTypeProvider"
/>
<typeProvider implementation="com.jetbrains.python.codeInsight.decorator.PyDecoratedFunctionTypeProvider"
id="pyDecoratedFunctionTypeProvider"/>
<typeProvider implementation="com.jetbrains.python.codeInsight.decorator.PyFunctoolsWrapsDecoratedFunctionTypeProvider"

View File

@@ -0,0 +1,12 @@
from dataclasses import dataclass
from typing import Generic
from typing_extensions import TypeVar
T = TypeVar('T', default=int)
@dataclass
class MyDataclass(Generic[T]):
x: T
MyDataclass(x=1)

View File

@@ -0,0 +1,12 @@
from dataclasses import dataclass
from typing import Generic
from typing_extensions import TypeVar
T = TypeVar('T', default=int)
@dataclass
class MyDataclass(Generic[T]):
x: T
MyDataclass(<warning descr="Parameter 'x' unfilled">)</warning>

View File

@@ -0,0 +1,12 @@
from dataclasses import dataclass
from typing import Generic
from typing import TypeVar
T = TypeVar('T')
@dataclass
class MyDataclass(Generic[T]):
x: T
MyDataclass(<arg1>)

View File

@@ -0,0 +1,12 @@
from dataclasses import dataclass
from typing import Generic
from typing import TypeVar
T = TypeVar('T', default=int)
@dataclass
class MyDataclass(Generic[T]):
x: T
MyDataclass(<arg1>)

View File

@@ -1351,6 +1351,22 @@ public class PyParameterInfoTest extends LightMarkedTestCase {
feignCtrlP(marks.get("<arg1>").getTextOffset()).check("id: int, name: str, year: int, new: bool", new String[]{"id: int, "});
}
// PY-78250
public void testInitializingGenericDataclassWithDefaultType() {
runWithLanguageLevel(LanguageLevel.PYTHON313, () -> {
final Map<String, PsiElement> marks = loadTest(1);
feignCtrlP(marks.get("<arg1>").getTextOffset()).check("x: T", new String[]{"x: T"});
});
}
// PY-78250
public void testInitializingGenericDataclass() {
runWithLanguageLevel(LanguageLevel.PYTHON313, () -> {
final Map<String, PsiElement> marks = loadTest(1);
feignCtrlP(marks.get("<arg1>").getTextOffset()).check("x: T", new String[]{"x: T"});
});
}
@NotNull
private Collector feignCtrlP(int offset) {
return feignCtrlP(offset, myFixture.getFile(), true, myFixture.getEditor());

View File

@@ -473,6 +473,16 @@ public class PyArgumentListInspectionTest extends PyInspectionTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON310, this::doTest);
}
// PY-78250
public void testInitializingGenericDataclassWithDefaultType() {
runWithLanguageLevel(LanguageLevel.PYTHON313, this::doTest);
}
// PY-78250
public void testInitializingGenericDataclassWithDefaultTypeNoArgument() {
runWithLanguageLevel(LanguageLevel.PYTHON313, this::doTest);
}
// PY-73102
public void testDeprecatedCall() {
doMultiFileTest("client.py");