mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Added support for using Literal
and various other special forms in a value expression. This addresses #7547. (#7969)
This commit is contained in:
parent
4c49f1b8cd
commit
be320a8b08
@ -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,
|
||||
|
@ -51,3 +51,6 @@ func1(TypeGuard)
|
||||
func1(Annotated)
|
||||
func1(Union[int, str])
|
||||
func1(int | str)
|
||||
|
||||
|
||||
{Literal[1]: "literal"}[Literal[1]]
|
||||
|
Loading…
Reference in New Issue
Block a user