From ee236052e3ed65ea388aa82958d0ce474aa42b33 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 17 Jun 2019 22:01:04 -0400 Subject: This class was simpler as a function --- coverage/bytecode.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'coverage/bytecode.py') diff --git a/coverage/bytecode.py b/coverage/bytecode.py index 943f29e1..ceb18cf3 100644 --- a/coverage/bytecode.py +++ b/coverage/bytecode.py @@ -6,17 +6,14 @@ import types -class CodeObjects(object): +def code_objects(code): """Iterate over all the code objects in `code`.""" - def __init__(self, code): - self.stack = [code] - - def __iter__(self): - while self.stack: - # We're going to return the code object on the stack, but first - # push its children for later returning. - code = self.stack.pop() - for c in code.co_consts: - if isinstance(c, types.CodeType): - self.stack.append(c) - yield code + stack = [code] + while stack: + # We're going to return the code object on the stack, but first + # push its children for later returning. + code = stack.pop() + for c in code.co_consts: + if isinstance(c, types.CodeType): + stack.append(c) + yield code -- cgit v1.2.1