Changed the way that PEP 695 type aliases are displayed when hovering over a reference to the type alias. Previously, the symbol was displayed as TypeAliasType rather than the expanded type alias type. This addresses #8147.

This commit is contained in:
Eric Traut 2024-06-15 19:03:12 +02:00
parent 6dc3b39902
commit 7ca7631808

View File

@ -1330,6 +1330,14 @@ export function createTypeEvaluator(
validateTypeIsInstantiable(typeResult, flags, node);
}
// If this is a PEP 695 type alias, remove the special form so the type
// printer prints it as its aliased type rather than TypeAliasType.
if ((flags & EvaluatorFlags.ExpectingTypeAnnotation) !== 0) {
if (typeResult.type.specialForm && ClassType.isBuiltIn(typeResult.type.specialForm, 'TypeAliasType')) {
typeResult.type = TypeBase.cloneAsSpecialForm(typeResult.type, undefined);
}
}
return typeResult;
}