* Fixed bug that results in a false negative when solving a type variable that involves an invariant context.

* Fixed a bug that can result in incorrect type inference for a subexpression that is part of an assignment expression if executed with an inference context (bidirectional type inference). This addresses #8054.
This commit is contained in:
Eric Traut 2024-06-03 11:24:06 -07:00 committed by GitHub
parent 5ac25c8256
commit 67fd972213
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 9 deletions

View File

@ -14622,11 +14622,11 @@ export function createTypeEvaluator(
assert(node.nodeType === ParseNodeType.ComprehensionIf);
// Evaluate the test expression to validate it and mark symbols
// as referenced. Don't bother doing this if we're in speculative
// mode because it doesn't affect the element type.
if (!isSpeculativeModeInUse(node.testExpression)) {
getTypeOfExpression(node.testExpression);
}
// as referenced. This doesn't affect the type of the evalauted
// comprehension, but it is important for evaluating intermediate
// expressions such as assignment expressions that can affect other
// subexpressions.
getTypeOfExpression(node.testExpression);
}
return isIncomplete;
@ -19721,7 +19721,7 @@ export function createTypeEvaluator(
}
case ParseNodeType.AssignmentExpression: {
getTypeOfExpression(curNode);
evaluateTypesForExpressionInContext(curNode);
return;
}

View File

@ -9,7 +9,7 @@ class ClassA:
output: str
def func1(foo: ClassA):
foo.output = "".join(
stripped for line in foo.input.splitlines() if (stripped := line.strip())
def func1(a: ClassA, x: str):
a.output = x.join(
stripped for line in a.input.splitlines() if (stripped := line.strip())
)