mirror of
https://github.com/microsoft/pyright.git
synced 2024-11-13 09:34:44 +03:00
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:
parent
1cb941f0cb
commit
120da9aa91
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user