From a442bfe0353973966b39eb8d2232bebeab38a9a7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 23 May 2024 07:39:15 -0700 Subject: [PATCH] Guard against unreachability --- conformance/results/mypy/specialtypes_promotions.toml | 10 +++++++--- conformance/results/mypy/version.toml | 2 +- conformance/results/pyre/specialtypes_promotions.toml | 4 +++- conformance/results/pyre/version.toml | 2 +- .../results/pyright/specialtypes_promotions.toml | 4 +++- conformance/results/pyright/version.toml | 2 +- .../results/pytype/specialtypes_promotions.toml | 10 +++++++--- conformance/results/pytype/version.toml | 2 +- conformance/results/results.html | 8 ++++---- conformance/tests/specialtypes_promotions.py | 6 +++++- 10 files changed, 33 insertions(+), 17 deletions(-) diff --git a/conformance/results/mypy/specialtypes_promotions.toml b/conformance/results/mypy/specialtypes_promotions.toml index f1a466553..04499e866 100644 --- a/conformance/results/mypy/specialtypes_promotions.toml +++ b/conformance/results/mypy/specialtypes_promotions.toml @@ -1,8 +1,12 @@ -conformant = "Pass" +conformant = "Partial" +notes = """ +Does not narrow from float to int after isinstance() check +""" output = """ specialtypes_promotions.py:17: error: "float" has no attribute "numerator" [attr-defined] -specialtypes_promotions.py:29: error: Incompatible return value type (got "complex", expected "float") [return-value] +specialtypes_promotions.py:33: error: Incompatible return value type (got "complex", expected "float") [return-value] """ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 26: Expected 1 errors """ diff --git a/conformance/results/mypy/version.toml b/conformance/results/mypy/version.toml index 9c6b57d39..dc9b55ed5 100644 --- a/conformance/results/mypy/version.toml +++ b/conformance/results/mypy/version.toml @@ -1,2 +1,2 @@ version = "mypy 1.10.0" -test_duration = 6.2 +test_duration = 1.5 diff --git a/conformance/results/pyre/specialtypes_promotions.toml b/conformance/results/pyre/specialtypes_promotions.toml index 4d57e8ce1..f17ad77f7 100644 --- a/conformance/results/pyre/specialtypes_promotions.toml +++ b/conformance/results/pyre/specialtypes_promotions.toml @@ -1,11 +1,13 @@ conformant = "Partial" notes = """ Does not reject use of attribute that is compatible only with float. +Does not narrow from float to int after isinstance() check """ output = """ -specialtypes_promotions.py:29:8 Incompatible return type [7]: Expected `float` but got `complex`. +specialtypes_promotions.py:33:8 Incompatible return type [7]: Expected `float` but got `complex`. """ conformance_automated = "Fail" errors_diff = """ Line 17: Expected 1 errors +Line 26: Expected 1 errors """ diff --git a/conformance/results/pyre/version.toml b/conformance/results/pyre/version.toml index 47c7ebccd..1fec89dee 100644 --- a/conformance/results/pyre/version.toml +++ b/conformance/results/pyre/version.toml @@ -1,2 +1,2 @@ version = "pyre 0.9.21" -test_duration = 2.6 +test_duration = 2.9 diff --git a/conformance/results/pyright/specialtypes_promotions.toml b/conformance/results/pyright/specialtypes_promotions.toml index da01e5ad0..560cb1193 100644 --- a/conformance/results/pyright/specialtypes_promotions.toml +++ b/conformance/results/pyright/specialtypes_promotions.toml @@ -2,7 +2,9 @@ conformant = "Pass" output = """ specialtypes_promotions.py:17:7 - error: Cannot access attribute "numerator" for class "float"   Attribute "numerator" is unknown (reportAttributeAccessIssue) -specialtypes_promotions.py:29:16 - error: Expression of type "complex" is incompatible with return type "float" +specialtypes_promotions.py:26:16 - error: Expression of type "Literal['x']" is incompatible with return type "int" +  "Literal['x']" is incompatible with "int" (reportReturnType) +specialtypes_promotions.py:33:16 - error: Expression of type "complex" is incompatible with return type "float"   "complex" is incompatible with "float" (reportReturnType) """ conformance_automated = "Pass" diff --git a/conformance/results/pyright/version.toml b/conformance/results/pyright/version.toml index f2385b55e..789c07a2b 100644 --- a/conformance/results/pyright/version.toml +++ b/conformance/results/pyright/version.toml @@ -1,2 +1,2 @@ version = "pyright 1.1.364" -test_duration = 1.8 +test_duration = 1.6 diff --git a/conformance/results/pytype/specialtypes_promotions.toml b/conformance/results/pytype/specialtypes_promotions.toml index 89270b31d..3d6ee0732 100644 --- a/conformance/results/pytype/specialtypes_promotions.toml +++ b/conformance/results/pytype/specialtypes_promotions.toml @@ -1,8 +1,12 @@ -conformant = "Pass" +conformant = "Partial" +notes = """ +Does not narrow from float to int after isinstance() check +""" output = """ File "specialtypes_promotions.py", line 17, in func1: No attribute 'numerator' on float [attribute-error] -File "specialtypes_promotions.py", line 29, in func2: bad return type [bad-return-type] +File "specialtypes_promotions.py", line 33, in func2: bad return type [bad-return-type] """ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 26: Expected 1 errors """ diff --git a/conformance/results/pytype/version.toml b/conformance/results/pytype/version.toml index 4c23eb4b6..bbfb29cda 100644 --- a/conformance/results/pytype/version.toml +++ b/conformance/results/pytype/version.toml @@ -1,2 +1,2 @@ version = "pytype 2024.04.11" -test_duration = 54.5 +test_duration = 49.8 diff --git a/conformance/results/results.html b/conformance/results/results.html index e0a66c34e..bc90bed9c 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -159,16 +159,16 @@

Python Type System Conformance Test Results

 
mypy 1.10.0
-
6.2sec
+
1.5sec
pyright 1.1.364
-
1.8sec
+
1.6sec
pyre 0.9.21
-
2.6sec
+
2.9sec
pytype 2024.04.11
-
54.5sec
+
49.8sec
diff --git a/conformance/tests/specialtypes_promotions.py b/conformance/tests/specialtypes_promotions.py index 64e728cfb..0216337df 100644 --- a/conformance/tests/specialtypes_promotions.py +++ b/conformance/tests/specialtypes_promotions.py @@ -13,13 +13,17 @@ v4 = 1 -def func1(f: float): +def func1(f: float) -> int: f.numerator # E: attribute exists on int but not float if isinstance(f, float): f.hex() # OK (attribute exists on float but not int) + return 1 else: assert_type(f, int) + # Make sure type checkers don't treat this branch as unreachable + # and skip checking it. + return "x" # E def func2(x: int) -> float: