-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added conformance tests for new "Exceptions" chapter. (#1724)
* Added conformance tests for new "Exceptions" chapter. * Incorporated Jelle's PR review feedback.
- Loading branch information
Showing
11 changed files
with
135 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
conformant = "Pass" | ||
errors_diff = """ | ||
""" | ||
output = """ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "mypy 1.9.0" | ||
test_duration = 1.5 | ||
test_duration = 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
conformant = "Pass" | ||
conformance_automated = "Pass" | ||
errors_diff = """ | ||
""" | ||
output = """ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "pyre 0.9.19" | ||
test_duration = 3.2 | ||
test_duration = 4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
conformant = "Pass" | ||
errors_diff = """ | ||
""" | ||
output = """ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "pyright 1.1.359" | ||
test_duration = 1.5 | ||
test_duration = 1.6 |
13 changes: 13 additions & 0 deletions
13
conformance/results/pytype/exceptions_context_managers.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "pytype 2024.04.11" | ||
test_duration = 35.1 | ||
test_duration = 35.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |