mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Reversed the change for #8035. Tuple expressions used in generators will not retain literal types.
This commit is contained in:
parent
d5b6abad59
commit
c7fbc82337
@ -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);
|
||||
}
|
||||
|
@ -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]")
|
||||
|
Loading…
Reference in New Issue
Block a user