Issue #16 resolved

Fixer for new style class

Haoyu Bai
created an issue

In Python 3, all classes defined is new style class, so

{{{ class Foo: pass }}}

is equivalent to Python 2 version of {{{ class Foo(object): pass }}}

It seems 3to2 didn't aware this yet.

Comments (4)

  1. Joe Amenta repo owner

    True. However, new-style classes were introduced in Python 2.2, and are (for now) beyond the scope of this project.

    In the future, 3to2 might be improved to generate code for older and older versions of Python, but for now, it's hard enough just to bridge the 3/2 gap that I am closing this as "wontfix".

  2. Haoyu Bai reporter

    You might misunderstood the issue. Sorry if I'm not clear. In py3k, old-style class is removed. So when we write "class Foo: pass" in Python 3, a new style class Foo is defined, which is equivalent to "class Foo(object): pass" in Python 2.x. Note that this is a difference between py3k and Python 2.x and not related to the introduction of new-style class in Python 2.2.

    For example, try the following code:

    class Foo: pass
    a = Foo()
    b = type(a)()

    It will run in Python 3 but raise exception in Python 2, which means in Python 2 'a' is not an 'object'(instance of new style class) but an 'instance'(instance of old style class).

    For a real world example you can try to run 3to2 on graphine ( Then run graphine's "CorrectnessTest" suite (inside you'll see the problem.\

    So what we need would be a fixer that turn "class Foo:..." to "class Foo(object):...". It should be easy, but very useful.

  3. Log in to comment