diff options
author | loic@dachary.org <loic@dachary.org> | 2016-12-15 18:33:16 +0100 |
---|---|---|
committer | loic@dachary.org <loic@dachary.org> | 2016-12-15 18:33:16 +0100 |
commit | 5c131498d140e172c5471929be4f30c65a200547 (patch) | |
tree | a02534e2f0b9269dea5aca1d8bde889ab859189e /coverage/parser.py | |
parent | 88207df5fa00861bf42f0993b23ce541817b72dd (diff) | |
download | python-coveragepy-git-5c131498d140e172c5471929be4f30c65a200547.tar.gz |
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
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 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") |