[TIP] figleaf tests
Ondrej Certik
ondrej at certik.cz
Tue Jun 24 04:53:59 PDT 2008
On Tue, Jun 24, 2008 at 1:42 PM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> I'm glad it worked out, but I'm confused by your code. I think all you need
> to do is take the set of linenumbers returned by dis.findlinestarts. Why do
> you need to walk the opcodes? I think this should work for your disassemble
> function:
>
> def disassemble(co):
> """Disassemble a code object and return line numbers."""
> code = co.co_code
> lines = set(l for (o, l) in dis.findlinestarts(co))
> for const in co.co_consts:
> if type(const) == types.CodeType:
> lines.update(disassemble(const))
> return lines
>
> It returns the same values as your code in the files I've run it on. (And
> maybe name it something other than disassemble! :-) ).
It's about these two lines in dis.dissasemble:
if op >= dis.HAVE_ARGUMENT:
i = i+2
I tried to comment them and on all files I tried it produced the
correct line numbers as you pointed out, but I think this skipping of
some lines are there for some reason, so I would like to know this
reason before removing it.
Ondrej
More information about the testing-in-python
mailing list