Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion mypy/erasetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ class LastKnownValueEraser(TypeTranslator):
def visit_instance(self, t: Instance) -> Type:
if not t.last_known_value and not t.args:
return t
return t.copy_modified(
new_t = t.copy_modified(
args=[a.accept(self) for a in t.args],
last_known_value=None,
)
new_t.can_be_true = t.can_be_true
new_t.can_be_false = t.can_be_false
return new_t

def visit_type_alias_type(self, t: TypeAliasType) -> Type:
# Type aliases can't contain literal values, because they are
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ b = bool()
reveal_type(s and b or b) # N: Revealed type is 'builtins.bool'
[builtins fixtures/bool.pyi]

[case testRestrictedBoolAndOrWithGenerics]
from typing import List

def f(a: List[str], b: bool) -> bool:
x = a and b
y: bool
return reveal_type(x or y) # N: Revealed type is 'builtins.bool'
[builtins fixtures/list.pyi]

[case testNonBooleanOr]
c, d, b = None, None, None # type: (C, D, bool)
if int():
Expand Down