IJ-MR-146029 PY-76149 code review changes and improvements

* Remove unnecessary descriptor type inference from `PyTargetExpressionImpl.getType`
* Refactor overload resolution for synthetic calls, minor refactorings in PyDescriptorTypeUtil
* Add additional test for __set__
* Do not substitute missing argument types with implicit `Any` in PySyntheticCallHelper
* Always take the first overload for `__set__` if more than one is present

(cherry picked from commit 9d1f9d37f3ea23ce6145f82fc8f62212f744e858)

GitOrigin-RevId: 372dc0e8ccc32095aecf3f611645adc06c2873e9
This commit is contained in:
Daniil Kalinin
2024-10-21 13:25:21 +02:00
committed by intellij-monorepo-bot
parent 0cb148129f
commit 0f40a088df
6 changed files with 80 additions and 28 deletions

View File

@@ -32,6 +32,30 @@ public class PySyntheticCallHelperTest extends PyTestCase {
});
}
public void testSimpleFunctionOnTopLevelTooFewArguments() {
doTest("int", """
def foo(x, y, z) -> int:
pass
""", () -> {
PyFunction function = myFixture.findElementByText("foo", PyFunction.class);
return PySyntheticCallHelper.getCallType(function, null, List.of(PyNoneType.INSTANCE),
TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()));
});
}
public void testSimpleFunctionOnTopLevelTooManyArguments() {
doTest("int", """
def foo(x) -> int:
pass
""", () -> {
PyFunction function = myFixture.findElementByText("foo", PyFunction.class);
return PySyntheticCallHelper.getCallType(function, null, List.of(PyNoneType.INSTANCE,
PyBuiltinCache.getInstance(myFixture.getFile()).getStrType(),
PyBuiltinCache.getInstance(myFixture.getFile()).getStrType()),
TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile()));
});
}
public void testSimpleFunctionWithOverloadsOnTopLevel() {
doTest("str", """
from typing import overload, Any

View File

@@ -2262,6 +2262,25 @@ def foo(param: str | int) -> TypeGuard[str]:
""");
}
// PY-76399
public void testAssignedValueMatchesWithDunderSetOfAttributeUsedInConstructor() {
doTestByText("""
class MyDescriptor:
def __set__(self, obj: object, value: str): ...
class Test:
member: MyDescriptor
def __init__(self, member):
self.member = member
x = Test("foo")
x.member = <warning descr="Expected type 'int' (from '__set__'), got 'str' instead">42</warning>
""");
}
// PY-23067
public void testFunctoolsWrapsMultiFile() {
doMultiFileTest();