[python] fix builtins.callable

Merge-request: IJ-MR-177060
Merged-by: Morgan Bartholomew <morgan.bartholomew@jetbrains.com>

GitOrigin-RevId: 2ec5c5ea1cc4183d757351f051b914a456ff15d8
This commit is contained in:
Morgan Bartholomew
2025-09-30 14:29:43 +00:00
committed by intellij-monorepo-bot
parent f02d90ff7c
commit eafca8d96d
3 changed files with 12 additions and 7 deletions
@@ -50,12 +50,6 @@ public class PyTypeAssertionEvaluator extends PyRecursiveElementVisitor {
transformTypeFromAssertion(context.getType(typeElement), false, context, typeElement));
}
}
else if (node.isCalleeText(PyNames.CALLABLE_BUILTIN)) {
final PyExpression[] args = node.getArguments();
if (args.length == 1) {
pushAssertion(args[0], myPositive, context -> PyTypingTypeProvider.createTypingCallableType(node));
}
}
else if (node.isCalleeText(PyNames.ISSUBCLASS)) {
final PyExpression[] args = node.getArguments();
if (args.length == 2) {
@@ -4161,6 +4161,15 @@ public class Py3TypeTest extends PyTestCase {
""");
}
@TestFor(issues="PY-84524")
public void testBuiltinsCallable() {
doTest("(...) -> object", """
a = object()
if callable(a):
expr = a
""");
}
private void doTest(final String expectedType, final String text) {
myFixture.configureByText(PythonFileType.INSTANCE, text);
final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
@@ -1980,7 +1980,9 @@ public class PyTypingTest extends PyTestCase {
// PY-79861
public void testWalrusCallable() {
doTest("type[Callable]",
// should actually be `(...) -> object` ... should actually be `Literal[42] & (...) -> object ... should actually be `Never`
// but we don't support this case yet
doTest("int",
"""
if callable(a := 42):
expr = a""");