Issue 2337: Backport oct() and hex() to use index (original) (raw)

Issue2337

Created on 2008-03-17 17:51 by brett.cannon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
oct_and_hex_py3k.patch benjamin.peterson,2008-04-27 19:04
Messages (11)
msg63695 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-03-17 17:51
oct() and hex() need to use __index__ when available and then emit a Py3K warning when they fall back on __oct__ and __hex__.
msg64270 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-21 20:13
Shouldn't we leave alone oct() and hex() (there is another issue for deprecation warning for __oct__ and __hex__), and let people use the versions from future_builtins?
msg65859 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-04-27 00:31
This is what I'd like to do: In builtin oct/hex check if the special method is declared. If it is, Py3k warn and use it. If not, check if we can do it the Py3k way (with PyNumber_ToBase). Sound good?
msg65863 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-04-27 01:23
@Georg: That is a possibility. Would need to add the proper Py3K warning to the current builtins, though. @Benjamin: You don't want to warn if it will work for Py3K, so don't warn if __index__ is used.
msg65865 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-04-27 01:26
I meant not to. Sorry, that wasn't clear.
msg65881 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-04-27 09:36
I don't assume there are too many people using oct() and hex() with custom types anyway :) Since PyNumber_ToBase and the new oct() format octal numbers with "0o" instead of "0", I still think it's better if you need to import the new oct() from future_builtins. For hex(), I have no preference.
msg65892 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-04-27 19:04
Here's a patch for that. It warns for hex() when __hex__ is used, otherwise it uses __index__. (This doesn't work for old style classes because ob_tp->tp_as_number->tp_hex is filled.) Use of oct() just gets a warning. The __hex__ and __oct__ methods of builtin number objects should probably be removed.
msg67008 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-17 18:49
The warning message for oct() should include that the output will be different too. Else this is fine with me.
msg67013 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-17 19:23
Done in r63425.
msg67015 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-17 20:11
I have reverted this. See mail.python.org/pipermail/python-checkins/2008-May/069843.html.
msg67768 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-06-06 14:18
This was rejected by Guido.
History
Date User Action Args
2022-04-11 14:56:31 admin set github: 46590
2008-06-06 14🔞08 benjamin.peterson set status: pending -> closedresolution: rejectedmessages: +
2008-05-17 20:36:02 eric.smith set nosy: + eric.smith
2008-05-17 20:11:48 benjamin.peterson set status: closed -> pendingresolution: fixed -> (no value)messages: +
2008-05-17 19:23:32 benjamin.peterson set status: open -> closedresolution: fixedmessages: +
2008-05-17 18:49:32 georg.brandl set messages: +
2008-04-27 19:08:36 benjamin.peterson link issue2352 superseder
2008-04-27 19:04:45 benjamin.peterson set files: + oct_and_hex_py3k.patchkeywords: + patchmessages: +
2008-04-27 09:36:27 georg.brandl set messages: +
2008-04-27 01:26:51 benjamin.peterson set messages: +
2008-04-27 01:23:42 brett.cannon set messages: +
2008-04-27 00:31:25 benjamin.peterson set nosy: + benjamin.petersonmessages: +
2008-03-21 20:13:50 georg.brandl set nosy: + georg.brandlmessages: +
2008-03-17 20:10:36 brett.cannon set priority: release blocker -> critical
2008-03-17 17:51:06 brett.cannon create