revert 63425 over Guido's Febuary message about this, that I missed

This commit is contained in:
Benjamin Peterson 2008-05-17 20:09:42 +00:00
parent d7943cb71d
commit c6d64ec83f
3 changed files with 15 additions and 45 deletions

View File

@ -632,10 +632,6 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(hex(-16L), '-0x10L') self.assertEqual(hex(-16L), '-0x10L')
self.assertRaises(TypeError, hex, {}) self.assertRaises(TypeError, hex, {})
class Spam(object):
def __index__(self): return 23
self.assertEqual(hex(Spam()), "0x17")
def test_id(self): def test_id(self):
id(None) id(None)
id(1) id(1)

View File

@ -123,20 +123,6 @@ class TestPy3KWarnings(unittest.TestCase):
with catch_warning() as w: with catch_warning() as w:
self.assertWarning(buffer('a'), w, expected) self.assertWarning(buffer('a'), w, expected)
def test_hex_and_oct(self):
class Spam(object):
def __hex__(self): return "0x17"
def __oct__(self): return "07"
expected = 'In 3.x, oct() converts the result of __index__ to octal; ' \
'Use future_builtins.oct for this behavior. ' \
'Also, note the returned format is different.'
with catch_warning() as w:
self.assertWarning(oct(Spam()), w, expected)
expected = 'In 3.x, hex() converts the result of __index__ to hexadecimal.'
with catch_warning() as w:
self.assertWarning(hex(Spam()), w, expected)
class TestStdlibRemovals(unittest.TestCase): class TestStdlibRemovals(unittest.TestCase):

View File

@ -1182,28 +1182,21 @@ builtin_hex(PyObject *self, PyObject *v)
PyNumberMethods *nb; PyNumberMethods *nb;
PyObject *res; PyObject *res;
nb = Py_TYPE(v)->tp_as_number; if ((nb = v->ob_type->tp_as_number) == NULL ||
nb->nb_hex == NULL) {
if (nb != NULL && nb->nb_hex != NULL) { PyErr_SetString(PyExc_TypeError,
if (PyErr_WarnPy3k("In 3.x, hex() converts " "hex() argument can't be converted to hex");
"the result of __index__ to hexadecimal.", return NULL;
1) < 0)
return NULL;
res = (*nb->nb_hex)(v);
if (res && !PyString_Check(res)) {
PyErr_Format(PyExc_TypeError,
"__hex__ returned non-string (type %.200s)",
res->ob_type->tp_name);
Py_DECREF(res);
return NULL;
}
return res;
} }
else if (PyIndex_Check(v)) res = (*nb->nb_hex)(v);
return PyNumber_ToBase(v, 16); if (res && !PyString_Check(res)) {
PyErr_SetString(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"hex() argument can't be converted to hex"); "__hex__ returned non-string (type %.200s)",
return NULL; res->ob_type->tp_name);
Py_DECREF(res);
return NULL;
}
return res;
} }
PyDoc_STRVAR(hex_doc, PyDoc_STRVAR(hex_doc,
@ -1463,11 +1456,6 @@ builtin_oct(PyObject *self, PyObject *v)
"oct() argument can't be converted to oct"); "oct() argument can't be converted to oct");
return NULL; return NULL;
} }
if (PyErr_WarnPy3k("In 3.x, oct() converts the result of __index__ to octal; "
"Use future_builtins.oct for this behavior. "
"Also, note the returned format is different.",
1) < 0)
return NULL;
res = (*nb->nb_oct)(v); res = (*nb->nb_oct)(v);
if (res && !PyString_Check(res)) { if (res && !PyString_Check(res)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,