Skip to content

Commit cce2f21

Browse files
committed
Issue 4910, patch 2 of (probably) 3: pave the way for renaming of
nb_long: remove last remaining use of nb_long (in the struct module) from the core, set nb_long slots on all builtin and extension types to 0, and remove uses of __long__ in test_complex and test_binop. Reviewed by Benjamin Peterson.
1 parent 29500f6 commit cce2f21

8 files changed

Lines changed: 8 additions & 25 deletions

File tree

Lib/test/test_binop.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ def __int__(self):
7777
repr(self))
7878
raise ValueError("can't convert %s to int" % repr(self))
7979

80-
def __long__(self):
81-
"""Convert a Rat to an long; self.den must be 1."""
82-
if self.__den == 1:
83-
return int(self.__num)
84-
raise ValueError("can't convert %s to long" % repr(self))
85-
8680
def __add__(self, other):
8781
"""Add two Rats, or a Rat and a number."""
8882
if isint(other):

Lib/test/test_cmath.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,9 @@ class NeitherComplexNorFloatOS:
182182
pass
183183
class MyInt(object):
184184
def __int__(self): return 2
185-
def __long__(self): return 2
186185
def __index__(self): return 2
187186
class MyIntOS:
188187
def __int__(self): return 2
189-
def __long__(self): return 2
190188
def __index__(self): return 2
191189

192190
# other possible combinations of __float__ and __complex__
@@ -219,7 +217,7 @@ def __float__(self):
219217
self.assertEqual(f(JustFloatOS()), f(flt_arg))
220218
# TypeError should be raised for classes not providing
221219
# either __complex__ or __float__, even if they provide
222-
# __int__, __long__ or __index__. An old-style class
220+
# __int__ or __index__. An old-style class
223221
# currently raises AttributeError instead of a TypeError;
224222
# this could be considered a bug.
225223
self.assertRaises(TypeError, f, NeitherComplexNorFloat())

Modules/_struct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ get_pylong(PyObject *v)
127127
return v;
128128
}
129129
m = Py_TYPE(v)->tp_as_number;
130-
if (m != NULL && m->nb_long != NULL) {
131-
v = m->nb_long(v);
130+
if (m != NULL && m->nb_int != NULL) {
131+
v = m->nb_int(v);
132132
if (v == NULL)
133133
return NULL;
134134
if (PyLong_Check(v))

Objects/complexobject.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,6 @@ complex_int(PyObject *v)
660660
return NULL;
661661
}
662662

663-
static PyObject *
664-
complex_long(PyObject *v)
665-
{
666-
PyErr_SetString(PyExc_TypeError,
667-
"can't convert complex to long; use long(abs(z))");
668-
return NULL;
669-
}
670-
671663
static PyObject *
672664
complex_float(PyObject *v)
673665
{
@@ -1068,7 +1060,7 @@ static PyNumberMethods complex_as_number = {
10681060
0, /* nb_xor */
10691061
0, /* nb_or */
10701062
complex_int, /* nb_int */
1071-
complex_long, /* nb_long */
1063+
0, /* nb_long */
10721064
complex_float, /* nb_float */
10731065
0, /* nb_inplace_add */
10741066
0, /* nb_inplace_subtract */

Objects/floatobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ static PyNumberMethods float_as_number = {
17981798
0, /*nb_xor*/
17991799
0, /*nb_or*/
18001800
float_trunc, /*nb_int*/
1801-
float_trunc, /*nb_long*/
1801+
0, /*nb_long*/
18021802
float_float, /*nb_float*/
18031803
0, /* nb_inplace_add */
18041804
0, /* nb_inplace_subtract */

Objects/longobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3830,7 +3830,7 @@ static PyNumberMethods long_as_number = {
38303830
long_xor, /*nb_xor*/
38313831
long_or, /*nb_or*/
38323832
long_long, /*nb_int*/
3833-
long_long, /*nb_long*/
3833+
0, /*nb_long*/
38343834
long_float, /*nb_float*/
38353835
0, /* nb_inplace_add */
38363836
0, /* nb_inplace_subtract */

Objects/weakrefobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ WRAP_BINARY(proxy_and, PyNumber_And)
489489
WRAP_BINARY(proxy_xor, PyNumber_Xor)
490490
WRAP_BINARY(proxy_or, PyNumber_Or)
491491
WRAP_UNARY(proxy_int, PyNumber_Int)
492-
WRAP_UNARY(proxy_long, PyNumber_Long)
493492
WRAP_UNARY(proxy_float, PyNumber_Float)
494493
WRAP_BINARY(proxy_iadd, PyNumber_InPlaceAdd)
495494
WRAP_BINARY(proxy_isub, PyNumber_InPlaceSubtract)
@@ -595,7 +594,7 @@ static PyNumberMethods proxy_as_number = {
595594
proxy_xor, /*nb_xor*/
596595
proxy_or, /*nb_or*/
597596
proxy_int, /*nb_int*/
598-
proxy_long, /*nb_long*/
597+
0, /*nb_long*/
599598
proxy_float, /*nb_float*/
600599
proxy_iadd, /*nb_inplace_add*/
601600
proxy_isub, /*nb_inplace_subtract*/

PC/winreg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static PyNumberMethods PyHKEY_NumberMethods =
451451
PyHKEY_binaryFailureFunc, /* nb_xor */
452452
PyHKEY_binaryFailureFunc, /* nb_or */
453453
PyHKEY_intFunc, /* nb_int */
454-
PyHKEY_unaryFailureFunc, /* nb_long */
454+
0, /* nb_long */
455455
PyHKEY_unaryFailureFunc, /* nb_float */
456456
};
457457

0 commit comments

Comments
 (0)