summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-05-17 19:21:20 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-05-17 19:21:20 (GMT)
commit79a922d6df18e0c0e508905aebc8f4fa28052aac (patch)
tree101822957ff56f5de4151af23c94caff7ba24f63 /Python
parent6c90c9faaeb20447df2e880f871ce10a80d2ff27 (diff)
downloadcpython-79a922d6df18e0c0e508905aebc8f4fa28052aac.zip
cpython-79a922d6df18e0c0e508905aebc8f4fa28052aac.tar.gz
cpython-79a922d6df18e0c0e508905aebc8f4fa28052aac.tar.bz2
add Py3k warnings to oct and hex. backport hex behavior (because it's not different)
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 0234b6b..5c30e03 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1181,22 +1181,29 @@ builtin_hex(PyObject *self, PyObject *v)
{
PyNumberMethods *nb;
PyObject *res;
-
- if ((nb = v->ob_type->tp_as_number) == NULL ||
- nb->nb_hex == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "hex() argument can't be converted to hex");
- 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;
+
+ nb = Py_TYPE(v)->tp_as_number;
+
+ if (nb != NULL && nb->nb_hex != NULL) {
+ if (PyErr_WarnPy3k("In 3.x, hex() converts "
+ "the result of __index__ to hexidecimal.",
+ 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;
}
- return res;
+ else if (PyIndex_Check(v))
+ return PyNumber_ToBase(v, 16);
+ PyErr_SetString(PyExc_TypeError,
+ "hex() argument can't be converted to hex");
+ return NULL;
}
PyDoc_STRVAR(hex_doc,
@@ -1456,6 +1463,11 @@ builtin_oct(PyObject *self, PyObject *v)
"oct() argument can't be converted to oct");
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);
if (res && !PyString_Check(res)) {
PyErr_Format(PyExc_TypeError,