summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-02-07 08:03:52 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-02-07 08:03:52 -0500
commitb8f054fcac467af98f23a8915df29a458437ad71 (patch)
treeb07ec3bed2554a6f05c0c5a5a5ecaec61e49f0b7
parent7ae0b1a079266ba71ee96cf61eb93f934e6f9ec3 (diff)
downloadpython-coveragepy-git-b8f054fcac467af98f23a8915df29a458437ad71.tar.gz
Properly handle {**{'a':1}} literals
-rw-r--r--coverage/parser.py9
-rw-r--r--tests/test_arcs.py33
2 files changed, 40 insertions, 2 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index e1f09c23..b73ac685 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -420,7 +420,12 @@ class AstArcAnalyzer(object):
def _line__Dict(self, node):
# Python 3.5 changed how dict literals are made.
if env.PYVERSION >= (3, 5) and node.keys:
- return node.keys[0].lineno
+ if node.keys[0] is not None:
+ return node.keys[0].lineno
+ else:
+ # Unpacked dict literals `{**{'a':1}}` have None as the key,
+ # use the value in that case.
+ return node.values[0].lineno
else:
return node.lineno
@@ -439,7 +444,7 @@ class AstArcAnalyzer(object):
OK_TO_DEFAULT = set([
"Assign", "Assert", "AugAssign", "Delete", "Exec", "Expr", "Global",
- "Import", "ImportFrom", "Pass", "Print",
+ "Import", "ImportFrom", "Nonlocal", "Pass", "Print",
])
def add_arcs(self, node):
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index 60cef938..56d65314 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -1034,6 +1034,39 @@ class MiscArcTest(CoverageTest):
arcz=".1 19 9-2",
)
+ def test_unpacked_literals(self):
+ if env.PYVERSION < (3, 5):
+ self.skip("Don't have unpacked literals until 3.5")
+ self.check_coverage("""\
+ d = {
+ 'a': 2,
+ 'b': 3,
+ }
+ weird = {
+ **d,
+ **{'c': 7},
+ 'd': 8,
+ }
+ assert weird['b'] == 3
+ """,
+ arcz=".1 15 5A A-2"
+ )
+ self.check_coverage("""\
+ l = [
+ 2,
+ 3,
+ ]
+ weird = [
+ *l,
+ *[7],
+ 8,
+ ]
+ assert weird[1] == 3
+ """,
+ arcz=".1 15 5A A-2"
+ )
+ 1/0
+
def test_pathologically_long_code_object(self):
# https://bitbucket.org/ned/coveragepy/issue/359
# The structure of this file is such that an EXTENDED_ARG bytecode is