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 rhettinger
Recipients gvanrossum, jyasskin, rhettinger
Date 2008-02-03.07:57:09
SpamBayes Score 0.061054833
Marked as misclassified No
Message-id <1202025431.87.0.450263532237.issue2002@psf.upfronthosting.co.za>
In-reply-to
Content
Guido, are these basically the mechanics you intended?  All calls to 
PyNumber_Int() and PyNumber_Long() attempt the usual path and if those 
would fail, it tries __trunc__ if it exists and coerces the result of 
that call back to an int or long.  

The logic looks basically correct, but I'm not sure what it buys us 
since the returned Integral has to be converted back to an int or long 
anyway.  On the plus side, it does not slow down the common case where 
PyNumber_Int() and PyNumberLong() would ordinarily succeed.  

An alternative to this patch would be to have math.trunc() try to 
return __trunc__() and if it doesn't exist, fallback to __int__.  That 
avoids having arbitrary Integrals forced back into ints/longs, but it 
may not be what you guys were after.

Either way will allow a user to define a __trunc__() method and have 
math.trunc() return an arbitrary Integral, not necessarily and int or 
long.

There is also part of this patch that touches classobject.c but I'm not 
yet sure what the visible effect of that change would be or what the 
change was hoping to accomplish.
History
Date User Action Args
2008-02-03 07:57:12rhettingersetspambayes_score: 0.0610548 -> 0.061054833
recipients: + rhettinger, gvanrossum, jyasskin
2008-02-03 07:57:11rhettingersetspambayes_score: 0.0610548 -> 0.0610548
messageid: <1202025431.87.0.450263532237.issue2002@psf.upfronthosting.co.za>
2008-02-03 07:57:10rhettingerlinkissue2002 messages
2008-02-03 07:57:10rhettingercreate