Fixed a bug that resulted in incorrect evaluation of a type alias defined with typing.TypeAlias and consisting of a single (naked) type variable. (#5527)

Co-authored-by: Eric Traut <erictr@microsoft.com>
This commit is contained in:
Eric Traut 2023-07-18 07:37:34 -07:00 committed by GitHub
parent 7924640f95
commit dc81efff28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -14592,12 +14592,9 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
// with this type alias.
typeParameters = [];
// Skip this for a simple TypeVar (one that's not part of a union).
if (!isTypeVar(type) || TypeBase.isAnnotated(type)) {
doForEachSubtype(type, (subtype) => {
addTypeVarsToListIfUnique(typeParameters!, getTypeVarArgumentsRecursive(subtype));
});
}
doForEachSubtype(type, (subtype) => {
addTypeVarsToListIfUnique(typeParameters!, getTypeVarArgumentsRecursive(subtype));
});
// Don't include any synthesized type variables.
typeParameters = typeParameters.filter((typeVar) => !typeVar.details.isSynthesized);

View File

@ -43,3 +43,10 @@ d: D_Alias[Any] = D()
item = d[0]
x: int = D_Alias[Any]()[0]
E: TypeAlias = _T
e1: E[int] = 3
# This should generate an error if reportMissingTypeArgument is enabled.
e2: E = 3

View File

@ -571,7 +571,7 @@ test('TypeAlias9', () => {
test('TypeAlias10', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['typeAlias10.py']);
TestUtils.validateResults(analysisResults, 4);
TestUtils.validateResults(analysisResults, 5);
});
test('TypeAlias11', () => {