This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ctl
Recipients ctl
Date 2008-01-01.02:38:26
SpamBayes Score 0.0010758102
Marked as misclassified No
Message-id <1199155109.22.0.179885625842.issue1716@psf.upfronthosting.co.za>
In-reply-to
Content
To reproduce:
>>> '%i' % 12345678901.0
TypeError: int argument required

Contrast with:
>>> '%i' % 1234567890.0
'1234567890'

Previous experience led me to expect that the '%i' format code would
work for all numerical types.  Admittedly, there's nothing in the docs
promising this, but it works *almost* all the time.

In fact, the operator fails to convert floats which are too big to fit
into a machine long.  The code for the '%i' operator handles objects of
type long specially, and then uses PyInt_AsLong to handle all other
objects (in formatint).

The ideal solution would be to ask the object to convert itself into an
int *before* the special test for type long; this would give the
expected behavior.

An acceptable solution would be to make the behavior consistent by
refusing all floats passed as the argument to '%i', but I expect this
would break a lot of code.  Of course, right now most of that code is
broken anyway, since it will throw a TypeError when the input float
happens to be large.
History
Date User Action Args
2008-01-01 02:38:29ctlsetspambayes_score: 0.00107581 -> 0.0010758102
recipients: + ctl
2008-01-01 02:38:29ctlsetspambayes_score: 0.00107581 -> 0.00107581
messageid: <1199155109.22.0.179885625842.issue1716@psf.upfronthosting.co.za>
2008-01-01 02:38:28ctllinkissue1716 messages
2008-01-01 02:38:27ctlcreate