mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Make bin() implementation parallel oct() and hex() so that int/long subclasses can override or so that other classes can support.
This commit is contained in:
parent
e0f124495b
commit
e3ae655edf
7 changed files with 49 additions and 2 deletions
|
|
@ -3743,6 +3743,7 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
|
|||
if (base->tp_flags & Py_TPFLAGS_HAVE_INDEX) {
|
||||
COPYNUM(nb_index);
|
||||
}
|
||||
COPYNUM(nb_hex);
|
||||
}
|
||||
|
||||
if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) {
|
||||
|
|
@ -5135,6 +5136,7 @@ slot_nb_coerce(PyObject **a, PyObject **b)
|
|||
SLOT0(slot_nb_int, "__int__")
|
||||
SLOT0(slot_nb_long, "__long__")
|
||||
SLOT0(slot_nb_float, "__float__")
|
||||
SLOT0(slot_nb_bin, "__bin__")
|
||||
SLOT0(slot_nb_oct, "__oct__")
|
||||
SLOT0(slot_nb_hex, "__hex__")
|
||||
SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O")
|
||||
|
|
@ -5802,6 +5804,8 @@ static slotdef slotdefs[] = {
|
|||
"long(x)"),
|
||||
UNSLOT("__float__", nb_float, slot_nb_float, wrap_unaryfunc,
|
||||
"float(x)"),
|
||||
UNSLOT("__bin__", nb_bin, slot_nb_bin, wrap_unaryfunc,
|
||||
"bin(x)"),
|
||||
UNSLOT("__oct__", nb_oct, slot_nb_oct, wrap_unaryfunc,
|
||||
"oct(x)"),
|
||||
UNSLOT("__hex__", nb_hex, slot_nb_hex, wrap_unaryfunc,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue