[Python-Dev] Draft Guide for code migration and modernation

Neal Norwitz neal@metaslash.com
Mon, 03 Jun 2002 15:32:53 -0400


Raymond Hettinger wrote:
> 
> Here is my cut at the migration and modernization guide.
> 
> Comments are welcome.
> 
> Walter and Neal, would you like to add the somewhat more involved steps for
> eliminating the types and strings modules.

Here's some more.  Note the last one.  Martin wanted to make sure this made
it into whatsnew.  I have already changed a few, one in Bdb I think.
I will be changing TclError also.  This could be a problem if anyone
assumed these exceptions would be string.

Neal
--

Pattern:  import types ; type(v, types.IntType)  -->  isinstance(v, int)
          type(s, types.StringTypes --> isinstance(s, basestring)
Idea:     The types module will likely to be deprecated in the future.
Version:  2.2 or greater
Benefits: May be slightly faster, avoid a deprecated feature.
Locating: grep types *.py | grep import

Pattern:  import string ; string.method(s, ...)  -->  s.method(...)
          c in string.whitespace --> c.isspace()
Idea:     The string module will likely to be deprecated in the future.
Version:  2.0 or greater
Benefits: Slightly faster, avoid a deprecated feature.
Locating: grep string *.py | grep import

Pattern:  NewError = 'NewError' --> class NewError(Exception): pass
Idea:     String exceptions are deprecated, derive from Exception base class.
Version:  Any
Benefits: String exceptions will not work in future versions.  Allows except Exception: clause to work.
Locating: Use PyChecker