-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new check for a common source of bugs where an equals operator …
…within an if statement compares two values whose literal types do not overlap and will therefore never evaluate to True.
- Loading branch information
1 parent
e91e976
commit 740ba46
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/pyright-internal/src/tests/samples/comparison1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This sample tests the check for non-overlapping types compared | ||
# with equals comparison. | ||
|
||
from typing import Literal | ||
|
||
|
||
OS = Literal["Linux", "Darwin", "Windows"] | ||
|
||
|
||
def func1(os: OS, val: Literal[1, "linux"]): | ||
if os == "Linux": | ||
return True | ||
|
||
# This should generate an error because there is no overlap in types. | ||
if os == "darwin": | ||
return False | ||
|
||
# This should generate an error because there is no overlap in types. | ||
if os == val: | ||
return False | ||
|
||
# This should generate an error because there is no overlap in types. | ||
if val == 2: | ||
return False | ||
|
||
if val == 1: | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters