This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: dis.dis function skips new-style classes in a module
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, dogeen
Priority: normal Keywords:

Created on 2010-04-04 12:57 by dogeen, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg102338 - (view) Author: Ozgur Dogan Ugurlu (dogeen) Date: 2010-04-04 12:57
The documentation says:

dis.dis([bytesource])
Disassemble the bytesource object. bytesource can denote either a module, a class, a method, a function, or a code object. For a module, it disassembles all functions. For a class, it disassembles all methods. For a single code sequence, it prints one line per bytecode instruction. If no object is provided, it disassembles the last traceback.

And the behavior is correct for old-style classes. However, since the if check in the function dis.dis is like this:

if hasattr(x, '__dict__'):
        items = x.__dict__.items()
        items.sort()
        for name, x1 in items:
            if type(x1) in (types.MethodType,
                            types.FunctionType,
                            types.CodeType,
                            types.ClassType):

when given a module (x), it doesn't handle new-style classes which are types.TypeType. (types.ClassType are old-style classes)

A simple addition of types.TypeType to the list used by the inner if clause fixes the problem for me but I don't know if it could introduce another bug.
msg102357 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-04-04 23:24
Fixed in r79769.
History
Date User Action Args
2022-04-11 14:56:59adminsetgithub: 52557
2010-04-04 23:24:00benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg102357

resolution: fixed
2010-04-04 12:57:31dogeencreate