-
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.
- Loading branch information
Showing
11 changed files
with
145 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,7 @@ | ||
conformant = "Pass" | ||
errors_diff = """ | ||
""" | ||
output = """ | ||
exceptions_context_managers.py:50: error: No return value expected [return-value] | ||
exceptions_context_managers.py:57: error: No return value expected [return-value] | ||
""" |
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.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,11 @@ | ||
conformant = "Unsupported" | ||
notes = """ | ||
Does not support code flow analysis. | ||
""" | ||
conformance_automated = "Fail" | ||
errors_diff = """ | ||
Line 50: Expected 1 errors | ||
Line 57: Expected 1 errors | ||
""" | ||
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.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,9 @@ | ||
conformant = "Pass" | ||
errors_diff = """ | ||
""" | ||
output = """ | ||
exceptions_context_managers.py:50:12 - error: Expression of type "Literal[1]" is incompatible with return type "None" | ||
"Literal[1]" is incompatible with "None" (reportReturnType) | ||
exceptions_context_managers.py:57:12 - error: Expression of type "Literal[1]" is incompatible with return type "None" | ||
"Literal[1]" is incompatible with "None" (reportReturnType) | ||
""" |
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 |
12 changes: 12 additions & 0 deletions
12
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,12 @@ | ||
conformant = "Unsupported" | ||
notes = """ | ||
Does not support code flow analysis. | ||
""" | ||
conformance_automated = "Fail" | ||
errors_diff = """ | ||
Line 50: Expected 1 errors | ||
Line 57: Expected 1 errors | ||
""" | ||
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 = "pytype 2024.04.11" | ||
test_duration = 35.1 | ||
test_duration = 35.9 |
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 | ||
|
||
|
||
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 func1() -> None: | ||
with Suppress1(): | ||
raise ValueError("This exception is suppressed") | ||
|
||
return 1 # E | ||
|
||
|
||
def func2() -> None: | ||
with Suppress2(): | ||
raise ValueError("This exception is suppressed") | ||
|
||
return 1 # E | ||
|
||
|
||
def func3() -> None: | ||
with NoSuppress1(): | ||
raise ValueError("This exception is not suppressed") | ||
|
||
return 1 # OK | ||
|
||
|
||
def func4() -> None: | ||
with NoSuppress2(): | ||
raise ValueError("This exception is not suppressed") | ||
|
||
return 1 # OK | ||
|
||
|
||
def func5() -> None: | ||
with NoSuppress3(): | ||
raise ValueError("This exception is not suppressed") | ||
|
||
return 1 # OK | ||
|
||
|
||
def func6() -> None: | ||
with NoSuppress4(): | ||
raise ValueError("This exception is not suppressed") | ||
|
||
return 1 # OK |