[Python-Dev] Disallow float arguments where an integer is expected in Python 2.7. (original) (raw)

Mark Dickinson dickinsm at gmail.com
Mon Dec 21 16:02:24 CET 2009


In Python 2.7, PyArg_ParseTuple and friends currently accept a float argument where an integer is expected, but produce a DeprecationWarning in this case. This can be seen in various places in Python proper:

itertools.combinations(range(5), 2.0) main:1: DeprecationWarning: integer argument expected, got float <itertools.combinations object at 0x10059f638>

Are there any objections to turning this DeprecationWarning into a TypeError for Python 2.7? The behaviour has been deprecated since Python 2.3, it's gone in 3.x, and having it produce an error in 2.7 might slightly reduce the number of surprises involved in porting from 2.x to 3.x. There's a patch at http://bugs.python.org/issue5080

There's one fly in the ointment: the deprecation warning is produced for all integer codes except for one---the 'L' code. The patch adds a deprecation warning for this code.

Mark



More information about the Python-Dev mailing list