Added special-case handling of values within enum classes in a py.typed package. They should be treated as constants and not require type annotations.

This commit is contained in:
Eric Traut 2020-09-23 18:54:59 -07:00
parent 1cb941f0cb
commit 120da9aa91

View File

@ -13352,7 +13352,18 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
return UnknownType.create();
}
if (!resolvedDecl.isFinal && !resolvedDecl.isConstant) {
// Special-case variables within an enum class. These are effectively
// constants, so we'll treat them as such.
const enclosingClass = ParseTreeUtils.getEnclosingClass(resolvedDecl.node, /* stopAtFunction */ true);
let isEnumValue = false;
if (enclosingClass) {
const classTypeInfo = getTypeOfClass(enclosingClass);
if (classTypeInfo && ClassType.isEnumClass(classTypeInfo.classType)) {
isEnumValue = true;
}
}
if (!resolvedDecl.isFinal && !resolvedDecl.isConstant && !isEnumValue) {
if (!resolvedDecl.typeAliasName) {
return UnknownType.create();
} else if (!resolvedDecl.typeAliasAnnotation) {