Reversed the change for #8035. Tuple expressions used in generators will not retain literal types.

This commit is contained in:
Eric Traut 2024-05-31 20:45:50 -07:00
parent d5b6abad59
commit c7fbc82337
2 changed files with 9 additions and 3 deletions

View File

@ -14521,15 +14521,21 @@ export function createTypeEvaluator(
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
const elementTypeResult = getElementTypeFromComprehension(node, flags, expectedEntryType);
const elementTypeResult = getElementTypeFromComprehension(
node,
flags | EvaluatorFlags.StripLiteralTypeForTuple,
expectedEntryType
);
if (elementTypeResult.isIncomplete) {
isIncomplete = true;
}
if (elementTypeResult.typeErrors) {
typeErrors = true;
}
let elementType = elementTypeResult.type;
let elementType = elementTypeResult.type;
if (!expectedEntryType || !containsLiteralType(expectedEntryType)) {
elementType = stripLiteralValue(elementType);
}

View File

@ -18,7 +18,7 @@ async def main() -> None:
reveal_type(v4, expected_text="AsyncGenerator[int, None]")
v5 = ((0, await foo()) for _ in [1, 2])
reveal_type(v5, expected_text="AsyncGenerator[tuple[Literal[0], int], None]")
reveal_type(v5, expected_text="AsyncGenerator[tuple[int, int], None]")
v6 = (x for x in [1, 2] if (x, await foo()))
reveal_type(v6, expected_text="AsyncGenerator[int, None]")