diff options
author | loic <loic@dachary.org> | 2016-12-15 18:33:16 +0100 |
---|---|---|
committer | loic <loic@dachary.org> | 2016-12-15 18:33:16 +0100 |
commit | 580e24f3cf0e991b400e1a254d7cc9220b0c1a4c (patch) | |
tree | fb1e1712e2c112aa353352577abf25df8735d2a9 /coverage/parser.py | |
parent | 65eefc5a62d5fae39921e7608039c1deff6be614 (diff) | |
download | python-coveragepy-580e24f3cf0e991b400e1a254d7cc9220b0c1a4c.tar.gz |
also use AST for while constants in python-2.7 #502issue-502-7
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
Diffstat (limited to 'coverage/parser.py')
-rw-r--r-- | coverage/parser.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index f65e4ab..e270851 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") |