mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-17 11:17:17 +03:00
Fixed bug in x is E
type narrowing pattern where E
is an enum literal and x
is a supertype of E
like object
. This addresses #8059. (#8062)
This commit is contained in:
parent
14a7622300
commit
46eba6ab41
@ -2543,7 +2543,8 @@ function narrowTypeForLiteralComparison(
|
||||
}
|
||||
} else if (isPositiveTest) {
|
||||
if (isIsOperator || isNoneInstance(subtype)) {
|
||||
return undefined;
|
||||
const isSubtype = evaluator.assignType(subtype, literalType);
|
||||
return isSubtype ? literalType : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,7 @@ class SomeEnum(Enum):
|
||||
VALUE2 = 2
|
||||
|
||||
|
||||
def assert_never(val: NoReturn):
|
||||
...
|
||||
def assert_never(val: NoReturn): ...
|
||||
|
||||
|
||||
def func1(a: SomeEnum):
|
||||
@ -69,3 +68,10 @@ def func7(a: Union[str, bool]) -> str:
|
||||
elif a is True:
|
||||
return "True"
|
||||
return a
|
||||
|
||||
|
||||
def func8(a: object):
|
||||
if a is SomeEnum.VALUE1 or a is SomeEnum.VALUE2:
|
||||
reveal_type(a, expected_text="Literal[SomeEnum.VALUE1, SomeEnum.VALUE2]")
|
||||
else:
|
||||
reveal_type(a, expected_text="object")
|
||||
|
Loading…
Reference in New Issue
Block a user