mirror of
https://github.com/microsoft/pyright.git
synced 2024-11-03 21:30:08 +03:00
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:
parent
7924640f95
commit
dc81efff28
@ -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);
|
||||
|
@ -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
|
||||
|
@ -571,7 +571,7 @@ test('TypeAlias9', () => {
|
||||
test('TypeAlias10', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['typeAlias10.py']);
|
||||
|
||||
TestUtils.validateResults(analysisResults, 4);
|
||||
TestUtils.validateResults(analysisResults, 5);
|
||||
});
|
||||
|
||||
test('TypeAlias11', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user