summaryrefslogtreecommitdiff
path: root/coverage/parser.py
diff options
context:
space:
mode:
authorNed Batchelder <nedbat@gmail.com>2016-12-24 15:04:22 -0500
committerNed Batchelder <nedbat@gmail.com>2016-12-24 15:04:22 -0500
commit5d4f399607fd711a1fb11d7c011f4466c6f50603 (patch)
treea02534e2f0b9269dea5aca1d8bde889ab859189e /coverage/parser.py
parent88207df5fa00861bf42f0993b23ce541817b72dd (diff)
parent5c131498d140e172c5471929be4f30c65a200547 (diff)
downloadpython-coveragepy-git-5d4f399607fd711a1fb11d7c011f4466c6f50603.tar.gz
Merged in dachary/coverage.py/issue-502-7 (pull request #117)
also use AST for while constants in python-2.7 #502
Diffstat (limited to 'coverage/parser.py')
-rw-r--r--coverage/parser.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index f65e4abb..e2708519 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -644,11 +644,12 @@ class AstArcAnalyzer(object):
"""Is this a compile-time constant?"""
node_name = node.__class__.__name__
if node_name in ["NameConstant", "Num"]:
- return True
+ return "Num"
elif node_name == "Name":
- if env.PY3 and node.id in ["True", "False", "None"]:
- return True
- return False
+ if (( env.PY3 or env.PYVERSION >= (2, 7)) and
+ node.id in ["True", "False", "None"]):
+ return "Name"
+ return None
# In the fullness of time, these might be good tests to write:
# while EXPR:
@@ -950,7 +951,7 @@ class AstArcAnalyzer(object):
def _handle__While(self, node):
constant_test = self.is_constant_expr(node.test)
start = to_top = self.line_for_node(node.test)
- if constant_test:
+ if constant_test and (env.PY3 or constant_test == "Num"):
to_top = self.line_for_node(node.body[0])
self.block_stack.append(LoopBlock(start=to_top))
from_start = ArcStart(start, cause="the condition on line {lineno} was never true")