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
8 changes: 6 additions & 2 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ i = None # type: str
j = not b and i
if j:
reveal_type(j) # E: Revealed type is 'builtins.str'


[builtins fixtures/bool.pyi]

[case testRestrictedTypeOr]
Expand All @@ -321,7 +319,13 @@ i = None # type: str
j = b or i
if not j:
reveal_type(j) # E: Revealed type is 'builtins.str'
[builtins fixtures/bool.pyi]

[case testAndOr]

s = ""
b = bool()
reveal_type(s and b or b) # E: Revealed type is 'builtins.bool'
[builtins fixtures/bool.pyi]

[case testNonBooleanOr]
Expand Down
21 changes: 21 additions & 0 deletions test-data/unit/check-isinstance.test
Original file line number Diff line number Diff line change
Expand Up @@ -1165,3 +1165,24 @@ reveal_type(l) # E: Revealed type is 'builtins.list[builtins.int*]'
reveal_type(g) # E: Revealed type is 'typing.Iterator[builtins.int*]'
reveal_type(d) # E: Revealed type is 'builtins.dict[builtins.int*, builtins.int*]'
[builtins fixtures/isinstancelist.pyi]

[case testIsinstanceInWrongOrderInBooleanOp]
class A:
m = 1
def f(x: object) -> None:
if x.m and isinstance(x, A) or False: # E: "object" has no attribute "m"
pass
[builtins fixtures/isinstance.pyi]
[out]
main: note: In function "f":

[case testIsinstanceAndOr]
class A:
a = None # type: A

def f(x: object) -> None:
b = isinstance(x, A) and x.a or A()
reveal_type(b) # E: Revealed type is '__main__.A'
[builtins fixtures/isinstance.pyi]
[out]
main: note: In function "f":
24 changes: 24 additions & 0 deletions test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ else:
reveal_type(x) # E: Revealed type is 'builtins.int'
[builtins fixtures/bool.pyi]

[case testOrCases]
from typing import Optional
x = None # type: Optional[str]
y1 = x or 'a'
reveal_type(y1) # E: Revealed type is 'builtins.str'
y2 = x or 1
reveal_type(y2) # E: Revealed type is 'Union[builtins.str, builtins.int]'
z1 = 'a' or x
reveal_type(z1) # E: Revealed type is 'Union[builtins.str, builtins.None]'
z2 = 1 or x
reveal_type(z2) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.None]'

[case testAndCases]
from typing import Optional
x = None # type: Optional[str]
y1 = x and 'b'
reveal_type(y1) # E: Revealed type is 'Union[builtins.str, builtins.None]'
y2 = x and 1 # x could be '', so...
reveal_type(y2) # E: Revealed type is 'Union[builtins.str, builtins.None, builtins.int]'
z1 = 'b' and x
reveal_type(z1) # E: Revealed type is 'Union[builtins.str, builtins.None]'
z2 = 1 and x
reveal_type(z2) # E: Revealed type is 'Union[builtins.int, builtins.str, builtins.None]'

[case testLambdaReturningNone]
f = lambda: None
x = f()
Expand Down