mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
PY-87340 AIOOBE: PyExpectedTypeJudgement.getElementTypeAtTupleIndex()
GitOrigin-RevId: 96f94b3827d5247d94108d945999d9c00c139a79
This commit is contained in:
committed by
intellij-monorepo-bot
parent
30cae884aa
commit
d6402476dd
@@ -462,21 +462,22 @@ object PyExpectedTypeJudgement {
|
||||
val elementTypes = tupleType.elementTypes
|
||||
val variadicRepeatCount = tupleExpr.elements.size - elementTypes.size + 1
|
||||
var arrayIdx = 0
|
||||
for (idx in 0 until tupleType.elementTypes.size) {
|
||||
val elemType = tupleType.elementTypes[idx]
|
||||
if (elemType is PyUnpackedTupleType && elemType.isUnbound) {
|
||||
repeat(variadicRepeatCount) {
|
||||
tupleTypeArray[arrayIdx++] = elemType.elementTypes.firstOrNull()
|
||||
for (elemType in elementTypes.take(tupleTypeArray.size)) {
|
||||
when (elemType) {
|
||||
is PyUnpackedTupleType if (elemType.isUnbound) -> {
|
||||
repeat(variadicRepeatCount) {
|
||||
tupleTypeArray[arrayIdx++] = elemType.elementTypes.firstOrNull()
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (elemType is PyTupleType && elemType.isHomogeneous) {
|
||||
repeat(variadicRepeatCount) {
|
||||
tupleTypeArray[arrayIdx++] = elemType.elementTypes.firstOrNull()
|
||||
is PyTupleType if (elemType.isHomogeneous) -> {
|
||||
repeat(variadicRepeatCount) {
|
||||
tupleTypeArray[arrayIdx++] = elemType.elementTypes.firstOrNull()
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
tupleTypeArray[arrayIdx++] = elemType
|
||||
}
|
||||
continue
|
||||
}
|
||||
tupleTypeArray[arrayIdx++] = elemType
|
||||
}
|
||||
if (indexOfExpr < tupleTypeArray.size) {
|
||||
return tupleTypeArray[indexOfExpr]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.jetbrains.python
|
||||
|
||||
import com.intellij.idea.TestFor
|
||||
import com.intellij.openapi.util.RecursionManager
|
||||
import com.intellij.openapi.util.StackOverflowPreventedException
|
||||
import com.jetbrains.python.documentation.PythonDocumentationProvider
|
||||
@@ -1070,6 +1071,14 @@ class PyExpectedTypeJudgmentTest : PyTestCase() {
|
||||
""")
|
||||
}
|
||||
|
||||
@TestFor(issues = ["PY-87340"])
|
||||
fun testMismatchOfExpectedAndActualTupleSize() {
|
||||
doTest("x", "int", """
|
||||
def check() -> tuple[bool, int, int]:
|
||||
return true, x
|
||||
""")
|
||||
}
|
||||
|
||||
// Note: The return type of yield is not subject to the [PyExpectedTypeJudgement] computation.
|
||||
@Suppress("unused")
|
||||
fun do_not_testReturnFromYieldExpressionInTypedGenerator() {
|
||||
|
||||
Reference in New Issue
Block a user