Skip to content

Commit a442bfe

Browse files
committed
Guard against unreachability
1 parent 6155dbd commit a442bfe

File tree

10 files changed

+33
-17
lines changed

10 files changed

+33
-17
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Does not narrow from float to int after isinstance() check
4+
"""
25
output = """
36
specialtypes_promotions.py:17: error: "float" has no attribute "numerator" [attr-defined]
4-
specialtypes_promotions.py:29: error: Incompatible return value type (got "complex", expected "float") [return-value]
7+
specialtypes_promotions.py:33: error: Incompatible return value type (got "complex", expected "float") [return-value]
58
"""
6-
conformance_automated = "Pass"
9+
conformance_automated = "Fail"
710
errors_diff = """
11+
Line 26: Expected 1 errors
812
"""

conformance/results/mypy/version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "mypy 1.10.0"
2-
test_duration = 6.2
2+
test_duration = 1.5
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
conformant = "Partial"
22
notes = """
33
Does not reject use of attribute that is compatible only with float.
4+
Does not narrow from float to int after isinstance() check
45
"""
56
output = """
6-
specialtypes_promotions.py:29:8 Incompatible return type [7]: Expected `float` but got `complex`.
7+
specialtypes_promotions.py:33:8 Incompatible return type [7]: Expected `float` but got `complex`.
78
"""
89
conformance_automated = "Fail"
910
errors_diff = """
1011
Line 17: Expected 1 errors
12+
Line 26: Expected 1 errors
1113
"""

conformance/results/pyre/version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyre 0.9.21"
2-
test_duration = 2.6
2+
test_duration = 2.9

conformance/results/pyright/specialtypes_promotions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ conformant = "Pass"
22
output = """
33
specialtypes_promotions.py:17:7 - error: Cannot access attribute "numerator" for class "float"
44
  Attribute "numerator" is unknown (reportAttributeAccessIssue)
5-
specialtypes_promotions.py:29:16 - error: Expression of type "complex" is incompatible with return type "float"
5+
specialtypes_promotions.py:26:16 - error: Expression of type "Literal['x']" is incompatible with return type "int"
6+
  "Literal['x']" is incompatible with "int" (reportReturnType)
7+
specialtypes_promotions.py:33:16 - error: Expression of type "complex" is incompatible with return type "float"
68
  "complex" is incompatible with "float" (reportReturnType)
79
"""
810
conformance_automated = "Pass"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyright 1.1.364"
2-
test_duration = 1.8
2+
test_duration = 1.6
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Does not narrow from float to int after isinstance() check
4+
"""
25
output = """
36
File "specialtypes_promotions.py", line 17, in func1: No attribute 'numerator' on float [attribute-error]
4-
File "specialtypes_promotions.py", line 29, in func2: bad return type [bad-return-type]
7+
File "specialtypes_promotions.py", line 33, in func2: bad return type [bad-return-type]
58
"""
6-
conformance_automated = "Pass"
9+
conformance_automated = "Fail"
710
errors_diff = """
11+
Line 26: Expected 1 errors
812
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pytype 2024.04.11"
2-
test_duration = 54.5
2+
test_duration = 49.8

conformance/results/results.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ <h3>Python Type System Conformance Test Results</h3>
159159
<div class="table_container"><table><tbody>
160160
<tr><th class="col1">&nbsp;</th>
161161
<th class='tc-header'><div class='tc-name'>mypy 1.10.0</div>
162-
<div class='tc-time'>6.2sec</div>
162+
<div class='tc-time'>1.5sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.364</div>
165-
<div class='tc-time'>1.8sec</div>
165+
<div class='tc-time'>1.6sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.21</div>
168-
<div class='tc-time'>2.6sec</div>
168+
<div class='tc-time'>2.9sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.04.11</div>
171-
<div class='tc-time'>54.5sec</div>
171+
<div class='tc-time'>49.8sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">

conformance/tests/specialtypes_promotions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
v4 = 1
1414

1515

16-
def func1(f: float):
16+
def func1(f: float) -> int:
1717
f.numerator # E: attribute exists on int but not float
1818

1919
if isinstance(f, float):
2020
f.hex() # OK (attribute exists on float but not int)
21+
return 1
2122
else:
2223
assert_type(f, int)
24+
# Make sure type checkers don't treat this branch as unreachable
25+
# and skip checking it.
26+
return "x" # E
2327

2428

2529
def func2(x: int) -> float:

0 commit comments

Comments
 (0)