Skip to content

Commit 13af01b

Browse files
committed
Do the same for enum literals.
1 parent 55fb9a6 commit 13af01b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mypy/typeops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ def false_only(t: Type) -> ProperType:
791791
elif isinstance(t, Instance):
792792
if (t.type.is_final or t.type.is_enum) and state.strict_optional:
793793
return UninhabitedType(line=t.line)
794-
elif isinstance(t, LiteralType) and t.is_enum_literal():
794+
elif isinstance(t, LiteralType) and t.is_enum_literal() and state.strict_optional:
795795
return UninhabitedType(line=t.line)
796796

797797
new_t = copy_type(t)

test-data/unit/check-inference.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,19 @@ if not x:
19761976
x = C()
19771977
[builtins fixtures/dict.pyi]
19781978

1979+
[case testNoWrongUnreachableWarningWithNoStrictOptionalAndEnumLiteral]
1980+
# flags: --no-strict-optional --warn-unreachable
1981+
from enum import Enum
1982+
from typing import Literal, Optional
1983+
1984+
class E(Enum):
1985+
a = 1
1986+
1987+
x: Optional[Literal[E.a]]
1988+
if not x:
1989+
x = E.a
1990+
[builtins fixtures/dict.pyi]
1991+
19791992
[case testInferFromEmptyListWhenUsingInWithStrictEquality]
19801993
# flags: --strict-equality
19811994
def f() -> None:

0 commit comments

Comments
 (0)