Skip to content

Commit

Permalink
Fixed recent regression that results in a false positive when accessi…
Browse files Browse the repository at this point in the history
…ng an enum member from an instance of an enum class. This addresses #7926.
  • Loading branch information
erictraut committed May 16, 2024
1 parent 6d79c5c commit 1f16eb6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/pyright-internal/src/analyzer/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,15 @@ export function getTypeOfEnumMember(
return undefined;
}

if (TypeBase.isInstantiable(classType)) {
const type = transformTypeForEnumMember(evaluator, classType, memberName);
if (!type) {
return undefined;
}

const type = transformTypeForEnumMember(evaluator, classType, memberName);
if (type) {
return { type, isIncomplete };
}

if (TypeBase.isInstantiable(classType)) {
return undefined;
}

// Handle the special case of 'name' and 'value' members within an enum.
const literalValue = classType.literalValue;

Expand Down
3 changes: 3 additions & 0 deletions packages/pyright-internal/src/tests/samples/enum1.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,6 @@ class TestEnum20(Enum):
reveal_type(TestEnum20.A.value, expected_text="Literal[1]")
reveal_type(TestEnum20.B, expected_text="Literal[TestEnum20.B]")
reveal_type(TestEnum20.B.value, expected_text="Literal[2]")
reveal_type(TestEnum20.A.A.A, expected_text="Literal[TestEnum20.A]")
reveal_type(TestEnum20.A.B.A, expected_text="Literal[TestEnum20.A]")
reveal_type(TestEnum20.A.B, expected_text="Literal[TestEnum20.B]")

0 comments on commit 1f16eb6

Please sign in to comment.