Fixed bug that results in a false negative when a TypeAliasType object is used in a class pattern. This addresses #7485. (#7486)

This commit is contained in:
Eric Traut 2024-03-14 13:43:02 -06:00 committed by GitHub
parent d7dc004c78
commit 18243af812
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1771,7 +1771,13 @@ function wrapTypeInList(evaluator: TypeEvaluator, node: ParseNode, type: Type):
}
export function validateClassPattern(evaluator: TypeEvaluator, pattern: PatternClassNode) {
const exprType = evaluator.getTypeOfExpression(pattern.className, EvaluatorFlags.CallBaseDefaults).type;
let exprType = evaluator.getTypeOfExpression(pattern.className, EvaluatorFlags.CallBaseDefaults).type;
// If the expression is a type alias or other special form, treat it
// as the special form rather than the class.
if (exprType.specialForm) {
exprType = exprType.specialForm;
}
if (isAnyOrUnknown(exprType)) {
return;