[Python-Dev] Patches: 1 for the price of 10.

Titus Brown titus at caltech.edu
Thu Dec 23 09:28:19 CET 2004


-> > Apparently file.seek doesn't have this DeprecationWarning though..
-> > Strange, that.
-> >  >>> f.seek(3.6)
-> >  >>> f.tell()
-> > 3L
-> 
-> That's a bug. Who'll fix it?

Added:

+         if (PyFloat_Check(offobj))
+             PyErr_Warn(PyExc_DeprecationWarning,
+                        "integer argument expected, got float" );

see attached diff.  I also attached it to the patch at SourceForge,
with a comment, just to keep the record straight.

The DeprecationWarning wasn't given because a manual PyObject -->
int/long conversion was being done, rather than the usual conversion
implicit in ParseTuple.

Regression tests run w/o problem on RH 9.0/i386.  Now you get the
correct behavior:

--
>>> f = open('/dev/zero')
>>> f.seek(5)
>>> f.tell()
5L
>>> f.seek(5.2)
__main__:1: DeprecationWarning: integer argument expected, got float
>>> f.tell()
5L
--

This seems like a reasonable resolution to patch #1067760, to me...

cheers,
--titus
-------------- next part --------------
? Objects/.fileobject.c.swp
Index: Objects/fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.193
diff -c -c -r2.193 fileobject.c
*** Objects/fileobject.c	7 Nov 2004 14:15:28 -0000	2.193
--- Objects/fileobject.c	23 Dec 2004 08:19:20 -0000
***************
*** 462,467 ****
--- 462,472 ----
  	whence = 0;
  	if (!PyArg_ParseTuple(args, "O|i:seek", &offobj, &whence))
  		return NULL;
+ 
+         if (PyFloat_Check(offobj))
+             PyErr_Warn(PyExc_DeprecationWarning,
+                        "integer argument expected, got float" );
+         
  #if !defined(HAVE_LARGEFILE_SUPPORT)
  	offset = PyInt_AsLong(offobj);
  #else


More information about the Python-Dev mailing list