Fixed bug that caused incorrect results with --verifytypes when NewType was used to define a type prior to Python 3.9. This addresses https://github.com/microsoft/pyright/issues/4764.

This commit is contained in:
Eric Traut 2023-03-12 15:21:54 -06:00
parent 7c23b1afb8
commit a28fb5d560

View File

@ -20949,16 +20949,20 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
);
const callType = baseTypeResult.type;
if (
isInstantiableClass(callType) &&
ClassType.isBuiltIn(callType, [
'TypeVar',
'ParamSpec',
'TypeVarTuple',
'TypedDict',
'NamedTuple',
'NewType',
])
const exemptBuiltins = [
'TypeVar',
'ParamSpec',
'TypeVarTuple',
'TypedDict',
'NamedTuple',
'NewType',
];
if (isInstantiableClass(callType) && ClassType.isBuiltIn(callType, exemptBuiltins)) {
isUnambiguousType = true;
} else if (
isFunction(callType) &&
exemptBuiltins.some((name) => callType.details.builtInName === name)
) {
isUnambiguousType = true;
}