Why has 'dir()' changed in Python 2.2?

Dr. David Mertz mertz at gnosis.cx
Fri Feb 1 21:47:14 EST 2002


I just noticed a change in Python 2.2... that turns out to break my
[xml_pickle] module.  It shouldn't be hard to fix (although I *do* have
a decision to ponder about the best fix)... but I mostly wonder what the
thoughts behind the change were (it seems like it will break a lot of
code that is moderately introspective).

Here's a test program:

    % cat dir_change.py
    import sys
    class C:
        "The docstring for C"
        def __init__(self):
            self.foo = 3
            self.bar = "bar"
        def othermethod(self): pass
    o = C()
    print sys.version
    print dir(o)

Running it (2.1):

    % python dir_change.py
    2.1 (#0, Jun 17 2001, 11:51:05) [EMX GCC 2.8.1]
    ['bar', 'foo']

compared with (2.2):

    % python dir_change.py
    2.2 (#0, Dec 24 2001, 18:42:48) [EMX GCC 2.8.1]
    ['__doc__', '__init__', '__module__', 'bar', 'foo', 'othermethod']

Here's a few others FWIW:

    % python dir_change.py
    1.5.1 (#0, Sep 21 1998, 08:28:40) [VisualAge C/C++]
    ['bar', 'foo']

    % python dir_change.py
    1.5.2 (#0, Jun 27 1999, 11:23:01) [VisualAge C/C++]
    ['bar', 'foo']

    % python dir_change.py
    2.0.42-S1.2.23 (#0, Apr 25 2001, 20:59:49) [GNU C/C++]
    ['bar', 'foo']

    % jython dir_change.py
    2.0
    ['bar', 'foo']

Or even:

    # python dir_change.py
    2.1.1 (#1, Aug 13 2001, 19:37:40)
    [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-96)]
    ['bar', 'foo']

    # python1 dir_change.py
    1.5.2 (#1, Jul 5 2001, 03:02:19) [GCC 2.96 20000731 (Red Hat Linux 7.1 2
    ['bar', 'foo']

Or:

    > python dir_change.py
    2.2a2+ (#22, Sep  5 2001, 14:10:41) [MSC 32 bit (Intel)]
    ['__doc__', '__init__', '__module__', 'bar', 'foo', 'othermethod']

Ok, enough versions...

--
mertz@  | The specter of free information is haunting the `Net!  All the
gnosis  | powers of IP- and crypto-tyranny have entered into an unholy
.cx     | alliance...ideas have nothing to lose but their chains.  Unite
        | against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------





More information about the Python-list mailing list