On Wed, Apr 7, 2010 at 4:10 PM, geremy condra <debat...@gmail.com> wrote: > On Wed, Apr 7, 2010 at 10:53 AM, Tom Evans <tevans...@googlemail.com> wrote: >> [ Please keep me cc'ed, I'm not subscribed ] >> >> Hi all >> >> I've written a bunch of internal libraries for my company, and they >> all use two space indents, and I'd like to be more consistent and >> conform to PEP-8 as much as I can. >> >> My problem is I would like to be certain that any changes do not alter >> the logic of the libraries. When doing this in C, I would simply >> compile each module to an object file, calculate the MD5 of the object >> file, then make the whitespace changes, recompile the object file and >> compare the checksums. If the checksums match, then the files are >> equivalent. >> >> Is there any way to do something semantically the same as this with python? > > Probably the logical thing would be to run your test suite against > it, but assuming that's not an option, you could run the whole > thing through dis and check that the bytecode is identical. There's > probably an easier way to do this though. > > Geremy Condra >
dis looks like it may be interesting. I had looked a little at the bytecode, but only enough to rule out md5 sums as a solution. Looking closer at the bytecode for a simple module, it seems like only a few bytes change (see below for hexdumps of the pyc). So in this case, only bytes 5 and 6 changed, the rest of the file remains exactly the same. Looks like I need to do some digging to find out what those bytes mean. Cheers Tom 2 space indents: 00000000 d1 f2 0d 0a 51 a7 bc 4b 63 00 00 00 00 00 00 00 |....Q..Kc.......| 00000010 00 02 00 00 00 40 00 00 00 73 28 00 00 00 64 00 |.....@...s(...d.| 00000020 00 84 00 00 5a 00 00 65 01 00 64 01 00 6a 02 00 |....Z..e..d..j..| 00000030 6f 0e 00 01 65 00 00 65 02 00 83 01 00 01 6e 01 |o...e..e......n.| 00000040 00 01 64 02 00 53 28 03 00 00 00 63 01 00 00 00 |..d..S(....c....| 00000050 01 00 00 00 03 00 00 00 43 00 00 00 73 20 00 00 |........C...s ..| 00000060 00 64 01 00 47 48 7c 00 00 6f 10 00 01 68 01 00 |.d..GH|..o...h..| 00000070 64 02 00 64 01 00 36 47 48 6e 01 00 01 64 00 00 |d..d..6GHn...d..| 00000080 53 28 03 00 00 00 4e 74 05 00 00 00 68 65 6c 6c |S(....Nt....hell| 00000090 6f 74 05 00 00 00 77 6f 72 6c 64 28 00 00 00 00 |ot....world(....| 000000a0 28 01 00 00 00 74 03 00 00 00 62 61 72 28 00 00 |(....t....bar(..| 000000b0 00 00 28 00 00 00 00 73 0e 00 00 00 74 65 73 74 |..(....s....test| 000000c0 6c 69 62 2f 66 6f 6f 2e 70 79 74 03 00 00 00 66 |lib/foo.pyt....f| 000000d0 6f 6f 01 00 00 00 73 08 00 00 00 00 01 05 01 07 |oo....s.........| 000000e0 01 03 01 74 08 00 00 00 5f 5f 6d 61 69 6e 5f 5f |...t....__main__| 000000f0 4e 28 03 00 00 00 52 03 00 00 00 74 08 00 00 00 |N(....R....t....| 00000100 5f 5f 6e 61 6d 65 5f 5f 74 04 00 00 00 54 72 75 |__name__t....Tru| 00000110 65 28 00 00 00 00 28 00 00 00 00 28 00 00 00 00 |e(....(....(....| 00000120 73 0e 00 00 00 74 65 73 74 6c 69 62 2f 66 6f 6f |s....testlib/foo| 00000130 2e 70 79 74 08 00 00 00 3c 6d 6f 64 75 6c 65 3e |.pyt....<module>| 00000140 01 00 00 00 73 04 00 00 00 09 07 0d 01 |....s........| 0000014d 4 space indents: 00000000 d1 f2 0d 0a 51 a7 bc 4b 63 00 00 00 00 00 00 00 |....Q..Kc.......| 00000010 00 02 00 00 00 40 00 00 00 73 28 00 00 00 64 00 |.....@...s(...d.| 00000020 00 84 00 00 5a 00 00 65 01 00 64 01 00 6a 02 00 |....Z..e..d..j..| 00000030 6f 0e 00 01 65 00 00 65 02 00 83 01 00 01 6e 01 |o...e..e......n.| 00000040 00 01 64 02 00 53 28 03 00 00 00 63 01 00 00 00 |..d..S(....c....| 00000050 01 00 00 00 03 00 00 00 43 00 00 00 73 20 00 00 |........C...s ..| 00000060 00 64 01 00 47 48 7c 00 00 6f 10 00 01 68 01 00 |.d..GH|..o...h..| 00000070 64 02 00 64 01 00 36 47 48 6e 01 00 01 64 00 00 |d..d..6GHn...d..| 00000080 53 28 03 00 00 00 4e 74 05 00 00 00 68 65 6c 6c |S(....Nt....hell| 00000090 6f 74 05 00 00 00 77 6f 72 6c 64 28 00 00 00 00 |ot....world(....| 000000a0 28 01 00 00 00 74 03 00 00 00 62 61 72 28 00 00 |(....t....bar(..| 000000b0 00 00 28 00 00 00 00 73 0e 00 00 00 74 65 73 74 |..(....s....test| 000000c0 6c 69 62 2f 66 6f 6f 2e 70 79 74 03 00 00 00 66 |lib/foo.pyt....f| 000000d0 6f 6f 01 00 00 00 73 08 00 00 00 00 01 05 01 07 |oo....s.........| 000000e0 01 03 01 74 08 00 00 00 5f 5f 6d 61 69 6e 5f 5f |...t....__main__| 000000f0 4e 28 03 00 00 00 52 03 00 00 00 74 08 00 00 00 |N(....R....t....| 00000100 5f 5f 6e 61 6d 65 5f 5f 74 04 00 00 00 54 72 75 |__name__t....Tru| 00000110 65 28 00 00 00 00 28 00 00 00 00 28 00 00 00 00 |e(....(....(....| 00000120 73 0e 00 00 00 74 65 73 74 6c 69 62 2f 66 6f 6f |s....testlib/foo| 00000130 2e 70 79 74 08 00 00 00 3c 6d 6f 64 75 6c 65 3e |.pyt....<module>| 00000140 01 00 00 00 73 04 00 00 00 09 07 0d 01 |....s........| 0000014d python code: testlib/foo.py def foo(bar): print "hello" if bar: print { 'hello': 'world' } if __name__ == "__main__": foo(True) -- http://mail.python.org/mailman/listinfo/python-list