Fixed a bug that led to a false positive error when using a type alias within an __init__ or __hash__ method in a dataclass. This addresses https://github.com/microsoft/pyright/issues/4596.

This commit is contained in:
Eric Traut 2023-02-08 12:01:29 -08:00
parent ceb2a2d5a4
commit f3a7ba79f1

View File

@ -16210,24 +16210,14 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
if (!skipSynthesizedInit) {
const initSymbol = lookUpClassMember(classType, '__init__', ClassMemberLookupFlags.SkipBaseClasses);
if (initSymbol) {
const initSymbolType = getTypeOfMember(initSymbol);
if (isFunction(initSymbolType)) {
if (!FunctionType.isSynthesizedMethod(initSymbolType)) {
hasExistingInitMethod = true;
}
} else {
hasExistingInitMethod = true;
}
hasExistingInitMethod = true;
}
}
let skipSynthesizeHash = false;
const hashSymbol = lookUpClassMember(classType, '__hash__', ClassMemberLookupFlags.SkipBaseClasses);
if (hashSymbol) {
const hashSymbolType = getTypeOfMember(hashSymbol);
if (isFunction(hashSymbolType) && !FunctionType.isSynthesizedMethod(hashSymbolType)) {
skipSynthesizeHash = true;
}
skipSynthesizeHash = true;
}
synthesizeDataClassMethods(