8000 Fix crash on TypeGuard plus "and" by JelleZijlstra · Pull Request #10496 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fix crash on TypeGuard plus "and" #10496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
proper implementation instead
  • Loading branch information
JelleZijlstra committed May 19, 2021
commit 892e6564cb5cea2df8cda5eade9dd45f6d7aaa58
7 changes: 6 additions & 1 deletion mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,12 @@ def visit_union_type(self, left: UnionType) -> bool:
return all([self._is_proper_subtype(item, self.orig_right) for item in left.items])

def visit_type_guard_type(self, left: TypeGuardType) -> bool:
raise RuntimeError("TypeGuard should not be used in subtype checks")
if isinstance(self.right, TypeGuardType):
# TypeGuard[bool] is a subtype of TypeGuard[int]
return self._is_proper_subtype(left.type_guard, self.right.type_guard)
else:
# TypeGuards aren't a subtype of anything else for now (but see #10489)
return False

def visit_partial_type(self, left: PartialType) -> bool:
# TODO: What's the right thing to do here?
Expand Down
0