[Python-checkins] r52738 - in python/trunk: Doc/lib/libstdtypes.tex Misc/NEWS Objects/fileobject.c

martin.v.loewis python-checkins at python.org
Sun Nov 12 19:24:27 CET 2006


Author: martin.v.loewis
Date: Sun Nov 12 19:24:26 2006
New Revision: 52738

Modified:
   python/trunk/Doc/lib/libstdtypes.tex
   python/trunk/Misc/NEWS
   python/trunk/Objects/fileobject.c
Log:
Bug #1067760: Deprecate passing floats to file.seek.


Modified: python/trunk/Doc/lib/libstdtypes.tex
==============================================================================
--- python/trunk/Doc/lib/libstdtypes.tex	(original)
+++ python/trunk/Doc/lib/libstdtypes.tex	Sun Nov 12 19:24:26 2006
@@ -1689,6 +1689,7 @@
   behavior.
 
   Note that not all file objects are seekable.
+  \versionchanged{Passing float values as offset has been deprecated}[2.6]
 \end{methoddesc}
 
 \begin{methoddesc}[file]{tell}{}

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Nov 12 19:24:26 2006
@@ -12,6 +12,8 @@
 Core and builtins
 -----------------
 
+- Bug #1067760: Deprecate passing floats to file.seek.
+
 - Bug #1591996: Correctly forward exception in instance_contains().
 
 - Bug #1588287: fix invalid assertion for `1,2` in debug builds.

Modified: python/trunk/Objects/fileobject.c
==============================================================================
--- python/trunk/Objects/fileobject.c	(original)
+++ python/trunk/Objects/fileobject.c	Sun Nov 12 19:24:26 2006
@@ -540,7 +540,7 @@
 	int whence;
 	int ret;
 	Py_off_t offset;
-	PyObject *offobj;
+	PyObject *offobj, *off_index;
 
 	if (f->f_fp == NULL)
 		return err_closed();
@@ -548,12 +548,25 @@
 	whence = 0;
 	if (!PyArg_ParseTuple(args, "O|i:seek", &offobj, &whence))
 		return NULL;
+	off_index = PyNumber_Index(offobj);
+	if (!off_index) {
+		if (!PyFloat_Check(offobj))
+			return NULL;
+		/* Deprecated in 2.6 */
+		PyErr_Clear();
+		if (PyErr_Warn(PyExc_DeprecationWarning,
+			       "integer argument expected, got float"))
+			return NULL;
+		off_index = offobj;
+		Py_INCREF(offobj);
+	}
 #if !defined(HAVE_LARGEFILE_SUPPORT)
-	offset = PyInt_AsLong(offobj);
+	offset = PyInt_AsLong(off_index);
 #else
-	offset = PyLong_Check(offobj) ?
-		PyLong_AsLongLong(offobj) : PyInt_AsLong(offobj);
+	offset = PyLong_Check(off_index) ?
+		PyLong_AsLongLong(off_index) : PyInt_AsLong(off_index);
 #endif
+	Py_DECREF(off_index);
 	if (PyErr_Occurred())
 		return NULL;
 


More information about the Python-checkins mailing list