[Python-Dev] dis module and new-style classes

Georg Brandl g.brandl at gmx.net
Thu Apr 6 21:21:09 CEST 2006


Guido van Rossum wrote:
> I think it's fine as it is. I don't think making it walk the
> inheritance tree is helpful; the output would be too large. Also, an
> instance doesn't have any code and that's fine too.

Inheritance has nothing to do with that.

> (Didn't you mean "dis.dis(D) doesn't touch C"?)

No.

> On 4/6/06, Georg Brandl <g.brandl at gmx.net> wrote:
>> Hi,
>>
>> dis.dis currently handles new-style classes stepmotherly: given
>>
>> class C(object):
>>   def Cm(): pass
>>   class D(object):
>>     def Dm(): pass
>>
>> dis.dis(C) doesn't touch D, and
>> dis.dis(C()) doesn't touch anything.
>>
>> Should it be fixed? It may need some reworking in dis.dis.

Here is an example transcript to make clearer what I mean:

Python 2.4.2 (#1, Mar 12 2006, 00:14:41)
>>> import dis
>>> class C:
...   def Cm(): pass
...   class D:
...     def Dm(): pass
...
>>> dis.dis(C)
Disassembly of Cm:
  2           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE

Disassembly of D:
Disassembly of Dm:
  4           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE


>>> dis.dis(C())
Disassembly of Cm:
  2           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE

Disassembly of D:
Disassembly of Dm:
  4           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE


>>> class Co(object):
...   def Cm(): pass
...   class Do(object):
...     def Dm(): pass
...
>>> dis.dis(Co)
Disassembly of Cm:
  2           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE

>>> dis.dis(Co())
>>>



More information about the Python-Dev mailing list