[Michael Hudson] > I've found another annoying problem. I'm not really expecting someone > here to sovle it for me, but writing it down might help me think > clearly. > > This is about the function epilogues that always get generated. I.e: > > >>> def f(): > ... if a: > ... print 1 > ... > >>> import dis > >>> dis.dis(f) > 2 0 LOAD_GLOBAL 0 (a) > 3 JUMP_IF_FALSE 9 (to 15) > 6 POP_TOP > > 3 7 LOAD_CONST 1 (1) > 10 PRINT_ITEM > 11 PRINT_NEWLINE > 12 JUMP_FORWARD 1 (to 16) > >> 15 POP_TOP > >> 16 LOAD_CONST 0 (None) > 19 RETURN_VALUE > > You can see here that the epilogue gets associated with line 3, > whereas it shouldn't really be associated with any line at all. It has to be associated with some line >= 3, as c_lnotab isn't capable of expressing anything other than that. It *could* associate it with "line 4", though, if the compiler were changed to pump out another c_lntab entry at the epilogue. That would be better than saying the time is charged to line 3, since it isn't on line 3 then. I'd be happy to trade away total insanity for partial insanity <wink>. > For why this is a problem: > > $ cat t.py > a = 0 > def f(): > if a: > print 1 > > >>> pdb.runcall(t.f) > > /home/mwh/src/sf/python/dist/src/build/t.py(3)f() > -> if a: > (Pdb) s > > /home/mwh/src/sf/python/dist/src/build/t.py(4)f() > -> print 1 > (Pdb) > --Return-- > > /home/mwh/src/sf/python/dist/src/build/t.py(4)f()->None > -> print 1 > (Pdb) > > The debugger stopping on the "print 1" is confusing. It stops on the "if a:" for me twice today, and I doubt that's any less confusing. If it were set to line 4 instead, an unaltered pdb would presumably show a blank line (whatever) after the function body, and an altered pdb could be taught that "the last line" c_lnotab claims exists is really devoted to exit code not associated with any source-file line.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4