new style classes and an IDLE "grump"

Paul M p.magwene at snet.net
Wed Mar 27 20:58:06 EST 2002


There is a minor (but somewhat unfortunate) difference in the way the IDLE
interpretter's "call tips" interact with "new" classes (i.e. classes derived
from object) and "classic" classes.  To see the difference try the
following:


>>> class Old:
        """An old style class (with sig)."""
        def __init__(self, x, y, z):
            pass


>>> class New(object):
        """A new style class (without sig)."""
        def __init__(self, x, y, z):
            pass


Now try instantiating an object of each of these classes while working in
IDLE.  For the classic class (Old) the idle prompt gives you a nice method
signature - "(x,y,z)" in this case, along with the doc string for the class.
The new style class doesn't give the same signature - only the doc string.

The method signature is a very nice feature when working with python
interactively - particularly for scientific computing.

The solution seems to be simply changing line 115 in CallTips.py (in the
Tools/Idle/ directory) as folows:

<         if type(ob)==types.ClassType:
---
>         if type(ob)==types.ClassType or type(ob) == types.TypeType:


This seems to "solve" the problem. However, is this the right solution -
i.e. is it only classes which are objects of type TypeType?  From my reading
of the "what's new" document I think this is the case, but it's late and my
brain is feeling a bit fuzzy.

Can somebody more up to date confirm or correct me on this matter?


Cheers,
Paul





More information about the Python-list mailing list