[python] Introduce PyArgumentsMapping.isComplete

GitOrigin-RevId: 64dca74e18a2ae8c4a64f6730093e59dbef6b671
This commit is contained in:
Mikhail Golubev
2024-10-15 22:19:26 +00:00
committed by intellij-monorepo-bot
parent d03f7bf818
commit 33919a56d0
4 changed files with 10 additions and 5 deletions
@@ -207,5 +207,12 @@ public interface PyCallExpression extends PyAstCallExpression, PyCallSiteExpress
public Map<PyExpression, PyCallableParameter> getMappedTupleParameters() {
return myMappedTupleParameters;
}
/**
* @return true if there are no unmapped parameters and no unmapped arguments, false otherwise
*/
public boolean isComplete() {
return getUnmappedParameters().isEmpty() && getUnmappedArguments().isEmpty();
}
}
}
@@ -262,7 +262,7 @@ public class PyTypeCheckerInspection extends PyInspection {
private void checkCallSite(@NotNull PyCallSiteExpression callSite) {
final List<AnalyzeCalleeResults> calleesResults = StreamEx
.of(mapArguments(callSite, getResolveContext()))
.filter(mapping -> mapping.getUnmappedArguments().isEmpty() && mapping.getUnmappedParameters().isEmpty())
.filter(mapping -> mapping.isComplete())
.map(mapping -> analyzeCallee(callSite, mapping))
.nonNull()
.toList();
@@ -399,7 +399,7 @@ class PyTypeHintsInspection : PyInspection() {
val resolveContext = PyResolveContext.defaultContext(myTypeEvalContext)
call
.multiMapArguments(resolveContext)
.firstOrNull { it.unmappedArguments.isEmpty() && it.unmappedParameters.isEmpty() }
.firstOrNull { it.isComplete }
?.let { mapping ->
mapping.mappedParameters.entries.forEach {
val name = it.value.name
@@ -1243,9 +1243,7 @@ public final class PyCallExpressionHelper {
@NotNull PyCallSiteExpression callSite,
@NotNull TypeEvalContext context) {
final PyCallExpression.PyArgumentsMapping fullMapping = mapArguments(callSite, callable, context);
if (!fullMapping.getUnmappedArguments().isEmpty() || !fullMapping.getUnmappedParameters().isEmpty()) {
return false;
}
if (!fullMapping.isComplete()) return false;
// TODO properly handle bidirectional operator methods, such as __eq__ and __neq__.
// Based only on its name, it's impossible to which operand is the receiver and which one is the argument.