From 5c131498d140e172c5471929be4f30c65a200547 Mon Sep 17 00:00:00 2001 From: "loic@dachary.org" Date: Thu, 15 Dec 2016 18:33:16 +0100 Subject: also use AST for while constants in python-2.7 #502 The node.id is set to False, True or None is python-2.7: there is no reason to only check for it with python-3. It is more reliable than using the DEFAULT_PARTIAL_ALWAYS regexps on source lines. close #502 --HG-- branch : issue-502-7 --- coverage/parser.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'coverage/parser.py') 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") -- cgit v1.2.1