Author: neal.norwitz
Date: Wed May 30 08:28:25 2007
New Revision: 55673
Modified:
python/branches/p3yk/Lib/dis.py
python/branches/p3yk/Lib/test/test_dis.py
Log:
Get the dis module working on modules again after changing dicts
to not return lists and also new-style classes. Add a test.
Modified: python/branches/p3yk/Lib/dis.py
==============================================================================
--- python/branches/p3yk/Lib/dis.py (original)
+++ python/branches/p3yk/Lib/dis.py Wed May 30 08:28:25 2007
@@ -23,13 +23,10 @@
if hasattr(x, '__code__'):
x = x.__code__
if hasattr(x, '__dict__'):
- items = x.__dict__.items()
- items.sort()
+ items = sorted(x.__dict__.items())
for name, x1 in items:
- if type(x1) in (types.MethodType,
- types.FunctionType,
- types.CodeType,
- types.ClassType):
+ if isinstance(x1, (types.MethodType, types.FunctionType,
+ types.CodeType, types.ClassType, type)):
print("Disassembly of %s:" % name)
try:
dis(x1)
@@ -41,9 +38,8 @@
elif isinstance(x, str):
disassemble_string(x)
else:
- raise TypeError, \
- "don't know how to disassemble %s objects" % \
- type(x).__name__
+ raise TypeError("don't know how to disassemble %s objects" %
+ type(x).__name__)
def distb(tb=None):
"""Disassemble a traceback (default: last traceback)."""
Modified: python/branches/p3yk/Lib/test/test_dis.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_dis.py (original)
+++ python/branches/p3yk/Lib/test/test_dis.py Wed May 30 08:28:25 2007
@@ -89,6 +89,18 @@
7 RETURN_VALUE
"""
+dis_module_expected_results = """\
+Disassembly of f:
+ 4 0 LOAD_CONST 0 (None)
+ 3 RETURN_VALUE
+
+Disassembly of g:
+ 5 0 LOAD_CONST 0 (None)
+ 3 RETURN_VALUE
+
+"""
+
+
class DisTests(unittest.TestCase):
def do_disassembly_test(self, func, expected):
s = StringIO.StringIO()
@@ -127,6 +139,7 @@
self.do_disassembly_test(bug708901, dis_bug708901)
def test_bug_1333982(self):
+ # XXX: re-enable this test!
# This one is checking bytecodes generated for an `assert` statement,
# so fails if the tests are run with -O. Skip this test then.
pass # Test has been disabled due to change in the way
@@ -153,9 +166,12 @@
expected = _BIG_LINENO_FORMAT % (i + 2)
self.do_disassembly_test(func(i), expected)
+ def test_big_linenos(self):
+ from test import dis_module
+ self.do_disassembly_test(dis_module, dis_module_expected_results)
+
def test_main():
run_unittest(DisTests)
-
if __name__ == "__main__":
test_main()
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins