[Python-Dev] Shortcut bugfix

Raymond Hettinger Raymond Hettinger" <python@rcn.com
Mon, 17 Mar 2003 20:36:04 -0500

There is an SF report that Pmw gets TypeErrors under Py2.3
but not under previous versions of Python:  www.python.org/sf/697591

There are three parts to the story:
1.   a method in _tkinter.c was changed (probably appropriately) to 
      occassionally return ints in addition to strings.

2.   Pmw used string.atoi() to coerce the result to an int.
      This should probably be changed, but I don't want
      existing Pmw to suddenly fail under 2.3.

3.   String.atoi(s)  works by calling int(s,10).  It is the
      ten part that makes int() raise a TypeError.

The long way to fix this bug is to 1) have Neal or MvL research the 
propriety of the changes to _tkinter and possibly find that they needed to
be done and have to be left alone and 2) have the Pmw folks
update their code to not use string.atoi(s) when s is not a string
(seems like a bug, but s used to always be a string when they
wrote the code).  Step 2 doesn't help existing users of Pmw
unless they get a bugfix release.

The shortcut is to fix something that isn't broken and have string.atoi
stop automatically appending the ten to the int() call.

Current string.atoi:
    def atoi(s, base=10):
        return _int(s, base)

Proposed string.atoi:
    def atoi(s, *args):
        return _int(s, *args)

The shortcut has some appeal because it lets the improvements
to _tkinter stay in place and allows existing Pmw installations
to continue to operate.  Otherwise, one of the two has to change.

Does anyone think changin string.atoi is the wrong way to go?

Raymond Hettinger