FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Keep known bool value when expanding bool to a union of literals by hsusul · Pull Request #22212 · python/mypy · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .test  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions mypy/typeops.py
This file contains hidden or 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
Expand Up @@ -1145,6 +1145,8 @@ class Status(Enum):
target_fullname is None or typ.type.fullname == target_fullname
):
if typ.type.fullname == "builtins.bool":
if typ.last_known_value is not None:
return typ.last_known_value
return UnionType([LiteralType(True, typ), LiteralType(False, typ)])

if typ.type.is_enum:
Expand Down
26 changes: 26 additions & 0 deletions test-data/unit/check-python310.test
This file contains hidden or 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
Expand Up @@ -1979,6 +1979,32 @@ def b(value: bool) -> int:
case False:
return 3

[case testMatchBoolLiteralSubjectExhaustive]
# flags: --strict-equality --warn-unreachable
def f() -> int:
match False:
case True:
return 1 # E: Statement is unreachable
case False:
return 0

def g(c: bool) -> int:
match True if c else False:
case True:
return 1
case False:
return 0

def h() -> int:
match False:
case True:
return 1 # E: Statement is unreachable
case False:
return 0
case other:
reveal_type(other) # E: Statement is unreachable
return 2

[case testMatchMiscNonExhaustiveReturn]
# flags: --strict-equality --warn-unreachable
class C:
Expand Down
Loading

Back | FazBrowse Home | New Git URL