[Patches] [ python-Patches-744321 ] Migrate to new-style classes

SourceForge.net noreply@sourceforge.net
Wed, 28 May 2003 04:40:51 -0700


Patches item #744321, was opened at 2003-05-27 15:13
Message generated for change (Comment added) made by jhylton
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=744321&group_id=5470

Category: Library (Lib)
Group: None
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Gerrit Holl (gerrit)
Assigned to: Nobody/Anonymous (nobody)
Summary: Migrate to new-style classes

Initial Comment:
This patch changes all old-style classes to new-style
classes in the standard library. This should be safe,
because all exceptions derive from Exception, so they
are not new-style classes as long as Exception isn't.,
and the exceptions module is built-in.

This can be wished to prevent class Foo(HTTPLib,
object) or similar. It is almost completely
backwards-compatible, although in some rare cases a
MRO-conflict may occur.

The script I used to do this is as follows:

#!/usr/bin/python

import re
import sys

pattern = "(^ *class [A-Za-z_][A-Za-z0-9_]*[^()]+)(:)"

for f in sys.argv[1:]:
    print "handling", f
    lines = open(f, 'r').readlines()
    fp = open(f, 'w')
    for line in lines:
        fp.write(re.sub(pattern, r"\1(object)\2", line))

...and...

$ python /tmp/repl.py $(find . -name "*.py" | grep -v
lib-old)
$ grep "^RCS " ~/newclass.diff | wc -l
    279
$ find . -name "*.py" | wc -l
    942


----------------------------------------------------------------------

>Comment By: Jeremy Hylton (jhylton)
Date: 2003-05-28 11:40

Message:
Logged In: YES 
user_id=31392

We'll do holistic refactoring of modules to upgrade them to
new-style classes, rather than a blanket change.  As you
note, new-style classes aren't semantically identical to
classic classes; the differences need to be accounted for.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=744321&group_id=5470