[Python-Dev] Re: [Python-checkins] python/dist/src/Objects stringobject.c,2.171,2.172
Guido van Rossum
guido@python.org
Sun, 28 Jul 2002 12:37:39 -0400
> Fredrik Lundh wrote:
> >
> > > SF patch #577031, remove PyArg_Parse() since it's deprecated
> >
> > > ! v = PyNumber_Float(v);
> > > ! if (!v)
> > > return -1;
> >
> > > v = PyNumber_Int(v);
> > > ! if (!v)
> > > return -1;
> >
> > umm.
> >
> > doesn't PyNumber_Float and PyNumber_Int convert its argument to
> > a float/integer, if it's not already the right type?
>
> Yes.
>
> > in earlier versions of Python, "%g" % "1.0" raised a TypeError. does
> > it still do that with this patch in place?
>
> No. :-( That wasn't an intentional change. The intent was
> to convert an int/long to a double in the case of '%g' et al and
> from a double to an int in the case of '%d'.
>
> What is the best way to fix this? If I call PyNumber_Check()
> before this code, the behaviour is the same as before.
Revert the change.
I don't believe PyNumber_Check() is the right thing to use here at all.
--Guido van Rossum (home page: http://www.python.org/~guido/)