diff options
-rw-r--r-- | coverage/parser.py | 5 | ||||
-rw-r--r-- | tests/test_arcs.py | 15 |
2 files changed, 19 insertions, 1 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index e4c86703..1c6e995a 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -708,7 +708,7 @@ class AstArcAnalyzer: # The node types that just flow to the next node with no complications. OK_TO_DEFAULT = { - "Assign", "Assert", "AugAssign", "Delete", "Exec", "Expr", "Global", + "AnnAssign", "Assign", "Assert", "AugAssign", "Delete", "Expr", "Global", "Import", "ImportFrom", "Nonlocal", "Pass", } @@ -904,6 +904,9 @@ class AstArcAnalyzer: # also call self.add_arc to record arcs they find. These functions mirror # the Python semantics of each syntactic construct. See the docstring # for add_arcs to understand the concept of exits from a node. + # + # Every node type that represents a statement should have a handler, or it + # should be listed in OK_TO_DEFAULT. @contract(returns='ArcStarts') def _handle__Break(self, node): diff --git a/tests/test_arcs.py b/tests/test_arcs.py index 8bf83008..905430e6 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -1659,6 +1659,21 @@ class AsyncTest(CoverageTest): ) +class AnnotationTest(CoverageTest): + """Tests using type annotations.""" + + def test_annotations(self): + self.check_coverage("""\ + def f(x:str, y:int) -> str: + a:int = 2 + return f"{x}, {y}, {a}, 3" + print(f("x", 4)) + """, + arcz=".1 .2 23 3. 14 4.", + ) + assert self.stdout() == "x, 4, 2, 3\n" + + class ExcludeTest(CoverageTest): """Tests of exclusions to indicate known partial branches.""" |