mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Fixed regression in --verifytypes
where variables assigned from calls to TypeVar
, ParamSpec
, TypeVarTuple
, NewType
, TypedDict
, and NamedTuple
were marked as ambiguous. This addresses https://github.com/microsoft/pyright/issues/4600.
This commit is contained in:
parent
6f07019c89
commit
f8edba07e5
@ -20839,9 +20839,33 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
|
||||
}
|
||||
}
|
||||
|
||||
// Special-case constants, which are treated as unambiguous.
|
||||
if (isFinalVariableDeclaration(resolvedDecl) || resolvedDecl.isConstant) {
|
||||
isUnambiguousType = true;
|
||||
}
|
||||
|
||||
// Special-case calls to certain built-in type functions.
|
||||
if (resolvedDecl.inferredTypeSource?.nodeType === ParseNodeType.Call) {
|
||||
const baseTypeResult = getTypeOfExpression(
|
||||
resolvedDecl.inferredTypeSource.leftExpression,
|
||||
EvaluatorFlags.DoNotSpecialize
|
||||
);
|
||||
const callType = baseTypeResult.type;
|
||||
|
||||
if (
|
||||
isInstantiableClass(callType) &&
|
||||
ClassType.isBuiltIn(callType, [
|
||||
'TypeVar',
|
||||
'ParamSpec',
|
||||
'TypeVarTuple',
|
||||
'TypedDict',
|
||||
'NamedTuple',
|
||||
'NewType',
|
||||
])
|
||||
) {
|
||||
isUnambiguousType = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user