diff options
author | Ran Benita <ran@unusedvar.com> | 2020-08-03 19:15:21 +0300 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2020-08-04 09:59:46 +0300 |
commit | 9ab14c6d9cc8318f62d14e0c49ca37a13972bd0e (patch) | |
tree | 2f8d1153454591e2e5d284d92b5bb996a00f488d /testing/test_assertrewrite.py | |
parent | 0dd5e169d0cfab2bee64fb6f463449d9347c489a (diff) | |
download | pytest-9ab14c6d9cc8318f62d14e0c49ca37a13972bd0e.tar.gz |
typing: set warn_unreachable
This makes mypy raise an error whenever it detects code which is
statically unreachable, e.g.
x: int
if isinstance(x, str):
... # Statement is unreachable [unreachable]
This is really neat and finds quite a few logic and typing bugs.
Sometimes the code is intentionally unreachable in terms of types, e.g.
raising TypeError when a function is given an argument with a wrong
type. In these cases a `type: ignore[unreachable]` is needed, but I
think it's a nice code hint.
Diffstat (limited to 'testing/test_assertrewrite.py')
-rw-r--r-- | testing/test_assertrewrite.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index 23f535173..63a6fdd12 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -381,7 +381,7 @@ class TestAssertionRewrite: ) def f7() -> None: - assert False or x() + assert False or x() # type: ignore[unreachable] assert ( getmsg(f7, {"x": x}) @@ -416,7 +416,7 @@ class TestAssertionRewrite: def test_short_circuit_evaluation(self) -> None: def f1() -> None: - assert True or explode # type: ignore[name-defined] # noqa: F821 + assert True or explode # type: ignore[name-defined,unreachable] # noqa: F821 getmsg(f1, must_pass=True) @@ -471,7 +471,7 @@ class TestAssertionRewrite: assert getmsg(f1) == "assert ((3 % 2) and False)" def f2() -> None: - assert False or 4 % 2 + assert False or 4 % 2 # type: ignore[unreachable] assert getmsg(f2) == "assert (False or (4 % 2))" |