diff --git a/conformance/results/mypy/exceptions_context_managers.toml b/conformance/results/mypy/exceptions_context_managers.toml new file mode 100644 index 000000000..cd630cbf5 --- /dev/null +++ b/conformance/results/mypy/exceptions_context_managers.toml @@ -0,0 +1,5 @@ +conformant = "Pass" +errors_diff = """ +""" +output = """ +""" diff --git a/conformance/results/mypy/version.toml b/conformance/results/mypy/version.toml index da96566e1..c8d80a45d 100644 --- a/conformance/results/mypy/version.toml +++ b/conformance/results/mypy/version.toml @@ -1,2 +1,2 @@ version = "mypy 1.9.0" -test_duration = 1.5 +test_duration = 2.0 diff --git a/conformance/results/pyre/exceptions_context_managers.toml b/conformance/results/pyre/exceptions_context_managers.toml new file mode 100644 index 000000000..be211bd5b --- /dev/null +++ b/conformance/results/pyre/exceptions_context_managers.toml @@ -0,0 +1,6 @@ +conformant = "Pass" +conformance_automated = "Pass" +errors_diff = """ +""" +output = """ +""" diff --git a/conformance/results/pyre/version.toml b/conformance/results/pyre/version.toml index 3c523460d..6c4e3accd 100644 --- a/conformance/results/pyre/version.toml +++ b/conformance/results/pyre/version.toml @@ -1,2 +1,2 @@ version = "pyre 0.9.19" -test_duration = 3.2 +test_duration = 4.1 diff --git a/conformance/results/pyright/exceptions_context_managers.toml b/conformance/results/pyright/exceptions_context_managers.toml new file mode 100644 index 000000000..cd630cbf5 --- /dev/null +++ b/conformance/results/pyright/exceptions_context_managers.toml @@ -0,0 +1,5 @@ +conformant = "Pass" +errors_diff = """ +""" +output = """ +""" diff --git a/conformance/results/pyright/version.toml b/conformance/results/pyright/version.toml index 767c25565..9c6229ed1 100644 --- a/conformance/results/pyright/version.toml +++ b/conformance/results/pyright/version.toml @@ -1,2 +1,2 @@ version = "pyright 1.1.359" -test_duration = 1.5 +test_duration = 1.6 diff --git a/conformance/results/pytype/exceptions_context_managers.toml b/conformance/results/pytype/exceptions_context_managers.toml new file mode 100644 index 000000000..5abf283a5 --- /dev/null +++ b/conformance/results/pytype/exceptions_context_managers.toml @@ -0,0 +1,13 @@ +conformant = "Unsupported" +notes = """ +Does not support code flow analysis. +""" +conformance_automated = "Fail" +errors_diff = """ +Line 50: Unexpected errors ['File "exceptions_context_managers.py", line 50, in suppress1: str [assert-type]'] +Line 57: Unexpected errors ['File "exceptions_context_managers.py", line 57, in suppress2: str [assert-type]'] +""" +output = """ +File "exceptions_context_managers.py", line 50, in suppress1: str [assert-type] +File "exceptions_context_managers.py", line 57, in suppress2: str [assert-type] +""" diff --git a/conformance/results/pytype/version.toml b/conformance/results/pytype/version.toml index 8c0b6d235..d16fadd1b 100644 --- a/conformance/results/pytype/version.toml +++ b/conformance/results/pytype/version.toml @@ -1,2 +1,2 @@ version = "pytype 2024.04.11" -test_duration = 35.1 +test_duration = 35.0 diff --git a/conformance/results/results.html b/conformance/results/results.html index 327802ee5..0c1ca92c0 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -159,16 +159,16 @@

Python Type System Conformance Test Results

+ + + + + + + diff --git a/conformance/src/test_groups.toml b/conformance/src/test_groups.toml index f23364cee..155287f48 100644 --- a/conformance/src/test_groups.toml +++ b/conformance/src/test_groups.toml @@ -47,6 +47,10 @@ href = "https://typing.readthedocs.io/en/latest/spec/constructors.html" name = "Overloads" href = "https://typing.readthedocs.io/en/latest/spec/overload.html" +[exceptions] +name = "Exceptions" +href = "https://typing.readthedocs.io/en/latest/spec/exceptions.html" + [dataclasses] name = "Dataclasses" href = "https://typing.readthedocs.io/en/latest/spec/dataclasses.html" diff --git a/conformance/tests/exceptions_context_managers.py b/conformance/tests/exceptions_context_managers.py new file mode 100644 index 000000000..774497220 --- /dev/null +++ b/conformance/tests/exceptions_context_managers.py @@ -0,0 +1,85 @@ +""" +Tests the handling of __exit__ return types for context managers. +""" + +# Specification: https://typing.readthedocs.io/en/latest/spec/exceptions.html + + +from typing import Any, Literal, assert_type + + +class CMBase: + def __enter__(self) -> None: + pass + + +class Suppress1(CMBase): + def __exit__(self, exc_type, exc_value, traceback) -> bool: + return True + + +class Suppress2(CMBase): + def __exit__(self, exc_type, exc_value, traceback) -> Literal[True]: + return True + + +class NoSuppress1(CMBase): + def __exit__(self, exc_type, exc_value, traceback) -> None: + return None + + +class NoSuppress2(CMBase): + def __exit__(self, exc_type, exc_value, traceback) -> Literal[False]: + return False + + +class NoSuppress3(CMBase): + def __exit__(self, exc_type, exc_value, traceback) -> Any: + return False + + +class NoSuppress4(CMBase): + def __exit__(self, exc_type, exc_value, traceback) -> None | bool: + return None + + +def suppress1(x: int | str) -> None: + if isinstance(x, int): + with Suppress1(): + raise ValueError + assert_type(x, int | str) + + +def suppress2(x: int | str) -> None: + if isinstance(x, int): + with Suppress2(): + raise ValueError + assert_type(x, int | str) + + +def no_suppress1(x: int | str) -> None: + if isinstance(x, int): + with NoSuppress1(): + raise ValueError + assert_type(x, str) + + +def no_suppress2(x: int | str) -> None: + if isinstance(x, int): + with NoSuppress2(): + raise ValueError + assert_type(x, str) + + +def no_suppress3(x: int | str) -> None: + if isinstance(x, int): + with NoSuppress3(): + raise ValueError + assert_type(x, str) + + +def no_suppress4(x: int | str) -> None: + if isinstance(x, int): + with NoSuppress4(): + raise ValueError + assert_type(x, str)
 
mypy 1.9.0
-
1.5sec
+
2.0sec
pyright 1.1.359
-
1.5sec
+
1.6sec
pyre 0.9.19
-
3.2sec
+
4.1sec
pytype 2024.04.11
-
35.1sec
+
35.0sec
@@ -667,6 +667,15 @@

Python Type System Conformance Test Results

Partial

Does not reject a function with a single @overload signature.

Does not reject a function with @overload signature but no implementation.

+Exceptions +
     exceptions_context_managersPassPass
Unsupported

Does not support code flow analysis.

Unsupported

Does not support code flow analysis.

Dataclasses
     dataclasses_descriptors