Added support for using Literal and various other special forms in a value expression. This addresses #7547. (#7969)

This commit is contained in:
Eric Traut 2024-05-21 12:20:01 -07:00 committed by GitHub
parent 4c49f1b8cd
commit be320a8b08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -20376,7 +20376,8 @@ export function createTypeEvaluator(
signatureTracker: UniqueSignatureTracker | undefined
): TypeResult {
if (arg.typeResult) {
return { type: arg.typeResult.type, isIncomplete: arg.typeResult.isIncomplete };
const type = arg.typeResult.type?.specialForm ?? arg.typeResult.type;
return { type, isIncomplete: arg.typeResult.isIncomplete };
}
if (!arg.valueExpression) {
@ -23733,8 +23734,19 @@ export function createTypeEvaluator(
return true;
}
if (
!isSpecialFormClass(expandedSrcType, flags) &&
if (isSpecialFormClass(expandedSrcType, flags)) {
if (destType.specialForm) {
return assignType(
destType.specialForm,
expandedSrcType,
diag,
destTypeVarContext,
srcTypeVarContext,
flags,
recursionCount
);
}
} else if (
assignClass(
destType,
expandedSrcType,

View File

@ -51,3 +51,6 @@ func1(TypeGuard)
func1(Annotated)
func1(Union[int, str])
func1(int | str)
{Literal[1]: "literal"}[Literal[1]]