PY-79330 Assertion fix

GitOrigin-RevId: 57599c47328eb97136b44e75c4e3341780e6ba50
This commit is contained in:
Petr
2025-05-30 17:56:15 +02:00
committed by intellij-monorepo-bot
parent 129c65214c
commit 613ca4396b
2 changed files with 23 additions and 8 deletions

View File

@@ -116,15 +116,17 @@ public final class PyStdlibTypeProvider extends PyTypeProviderBase {
PyClassType enumType = as(context.getType(qualifier), PyClassType.class);
if (enumType != null) {
PyClass enumClass = enumType.getPyClass();
PyTargetExpression firstEnumItem = ContainerUtil.getFirstItem(enumClass.getClassAttributes());
if (firstEnumItem != null) {
EnumAttributeInfo attributeInfo = getEnumAttributeInfo(enumClass, firstEnumItem, context);
if (attributeInfo != null) {
return Ref.create(attributeInfo.assignedValueType);
if (isCustomEnum(enumClass, context)) {
PyTargetExpression firstEnumItem = ContainerUtil.getFirstItem(enumClass.getClassAttributes());
if (firstEnumItem != null) {
EnumAttributeInfo attributeInfo = getEnumAttributeInfo(enumClass, firstEnumItem, context);
if (attributeInfo != null) {
return Ref.create(attributeInfo.assignedValueType);
}
}
else {
return Ref.create();
}
}
else {
return Ref.create();
}
}
}

View File

@@ -4163,6 +4163,19 @@ public class PyTypeTest extends PyTestCase {
);
}
// PY-79330
public void testTypeHintedEnumItemValueAttribute2() {
runWithLanguageLevel(
LanguageLevel.getLatest(),
() -> doTest("() -> Any", // Should be 'Any' PY-71603
"""
from enum import Enum
def f(p: Enum):
expr = p.value""")
);
}
// PY-54503
public void testImportedEnumGetItemResultValueAttribute() {
myFixture.copyDirectoryToProject(TEST_DIRECTORY + getTestName(false), "");