int (@Nullable final PyExpression rightExpression, @NotNull final PsiElement problemTarget) { final Class[] SIMPLE_RHS_EXPRESSIONS = { PyLiteralExpression.class, PySubscriptionExpression.class, PyBinaryExpression.class, PyConditionalExpression.class }; final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(problemTarget); final PyResolveContext resolveContext = PyResolveContext.defaultContext(myTypeEvalContext); final String s = myFormatSpec.get("1"); if (PsiTreeUtil.instanceOf(rightExpression, SIMPLE_RHS_EXPRESSIONS)) { if (s != null) { final PyType rightType = myTypeEvalContext.getType(rightExpression); if (rightType instanceof PyTupleType tupleType) { matchEntireTupleTypes(problemTarget, tupleType); return tupleType.getElementCount(); } else { checkExpressionType(rightExpression, s, problemTarget); } } return 1; } else if (rightExpression instanceof PyReferenceExpression) { if (PyNames.DUNDER_DICT.equals(rightExpression.getName())) return -1; final List<QualifiedRatedResolveResult> resolveResults = ((PyReferenceExpression)rightExpression).multiFollowAssignmentsChain(resolveContext); if (resolveResults.isEmpty()) { return -1; } final PsiElement pyElement = PyUtil.filterTopPriorityResults(resolveResults).get(0).getElement(); if (pyElement == rightExpression || !(pyElement instanceof PyExpression)) { return -1; } if (pyElement instanceof PyDictLiteralExpression) { return inspectDict(rightExpression, problemTarget, true); } return inspectArguments((PyExpression)pyElement, problemTarget); } else if (rightExpression instanceof PyCallExpression) { final PyExpression callee = ((PyCallExpression)rightExpression).getCallee(); if (callee != null && "dict".equals(callee.getName())) return 1; return inspectCallExpression((PyCallExpression)rightExpression, resolveContext, myTypeEvalContext); } else if (rightExpression instanceof PyParenthesizedExpression) { final PyExpression rhs = ((PyParenthesizedExpression)rightExpression).getContainedExpression(); if (rhs != null) { return inspectArguments(rhs, problemTarget); } } else if (rightExpression instanceof PyTupleExpression) { if (PsiTreeUtil.isAncestor(problemTarget, rightExpression, false)) { final PyExpression[] expressions = ((PyTupleExpression)rightExpression).getElements(); int i = 1; for (PyExpression expression : expressions) { final String formatSpec = myFormatSpec.get(Integer.toString(i)); if (formatSpec != null) { checkExpressionType(expression, formatSpec, expression); } ++i; } return expressions.length; } else { final PyTupleType tupleType = (PyTupleType)myTypeEvalContext.getType(rightExpression); assert tupleType != null; matchEntireTupleTypes(problemTarget, tupleType); return tupleType.getElementCount(); } } else if (rightExpression instanceof PyDictLiteralExpression) { return inspectDict(rightExpression, problemTarget, false); } else if (PsiTreeUtil.instanceOf(rightExpression, PySequenceExpression.class, PyComprehensionElement.class)) { if (s != null) { checkTypeCompatible(problemTarget, builtinCache.getStrType(), PyTypeParser.getTypeByName(problemTarget, s, myTypeEvalContext)); return 1; } } else if (rightExpression instanceof PySliceExpression && s != null) { final PyType type = myTypeEvalContext.getType(((PySliceExpression)rightExpression).getOperand()); final PyType stringType = PyBuiltinCache.getInstance(rightExpression).getStringType(LanguageLevel.forElement(rightExpression)); final PyType listType = PyBuiltinCache.getInstance(rightExpression).getListType(); if (type == null) return -1; if (PyTypeChecker.match(listType, type, myTypeEvalContext) || PyTypeChecker.match(stringType, type, myTypeEvalContext)) { checkTypeCompatible(problemTarget, builtinCache.getStrType(), PyTypeParser.getTypeByName(problemTarget, s, myTypeEvalContext)); return 1; } PySliceItem sliceItem = ((PySliceExpression)rightExpression).getSliceItem(); if (sliceItem != null) { PyExpression lower = sliceItem.getLowerBound(); PyExpression upper = sliceItem.getUpperBound(); PyExpression stride = sliceItem.getStride(); if (upper instanceof PyNumericLiteralExpression) { BigInteger lowerVal; if (lower instanceof PyNumericLiteralExpression) { lowerVal = ((PyNumericLiteralExpression)lower).getBigIntegerValue(); } else { lowerVal = BigInteger.ZERO; } int count = (((PyNumericLiteralExpression)upper).getBigIntegerValue().subtract(lowerVal)).intValue(); int strideVal; if (stride instanceof PyNumericLiteralExpression) { strideVal = ((PyNumericLiteralExpression)stride).getBigIntegerValue().intValue(); } else { strideVal = 1; } int res = count / strideVal; int residue = count % strideVal == 0 ? 0 : 1; return res + residue; } } return -1; } return -1; }