summaryrefslogtreecommitdiff
path: root/coverage/parser.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2020-09-12 16:33:13 -0400
committerNed Batchelder <ned@nedbatchelder.com>2020-09-12 16:33:13 -0400
commit1c13cb9cce73bf1e47977be89ef3b086e36ef3c8 (patch)
treee9ee8c4e244cc651575d066d5d3326dbd77539b2 /coverage/parser.py
parentc3159081ae67864f75aacc1b86310fe9d8d614cb (diff)
downloadpython-coveragepy-git-nedbat/test-2506.tar.gz
Adapt to https://github.com/python/cpython/pull/22027nedbat/test-2506
Diffstat (limited to 'coverage/parser.py')
-rw-r--r--coverage/parser.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index e3e43149..9b97589b 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -1111,7 +1111,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 and (env.PY3 or constant_test == "Num"):
+ if not env.NOOPT and 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")
@@ -1126,7 +1126,7 @@ class AstArcAnalyzer(object):
else_exits = self.add_body_arcs(node.orelse, from_start=from_start)
exits |= else_exits
else:
- # No `else` clause: you can exit from the start.
+ # No `else` clause: you can exit from the start if the condition isn't constant.
if not constant_test:
exits.add(from_start)
return exits