Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2dbecb

Browse files
committed
repr() of a long int no longer produces a trailing 'L'.
More unit tests probably need fixing; later...
1 parent f431278 commit d2dbecb

2 files changed

Lines changed: 10 additions & 18 deletions

File tree

Lib/test/test_long.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_bitop_identities(self):
196196
def slow_format(self, x, base):
197197
if (x, base) == (0, 8):
198198
# this is an oddball!
199-
return "0L"
199+
return "0"
200200
digits = []
201201
sign = 0
202202
if x < 0:
@@ -208,7 +208,7 @@ def slow_format(self, x, base):
208208
digits = digits or [0]
209209
return '-'[:sign] + \
210210
{8: '0', 10: '', 16: '0x'}[base] + \
211-
"".join(map(lambda i: "0123456789abcdef"[i], digits)) + "L"
211+
"".join(map(lambda i: "0123456789abcdef"[i], digits))
212212

213213
def check_format_1(self, x):
214214
for base, mapper in (8, oct), (10, repr), (16, hex):
@@ -221,7 +221,7 @@ def check_format_1(self, x):
221221
# str() has to be checked a little differently since there's no
222222
# trailing "L"
223223
got = str(x)
224-
expected = self.slow_format(x, 10)[:-1]
224+
expected = self.slow_format(x, 10)
225225
msg = Frm("%s returned %r but expected %r for %r",
226226
mapper.__name__, got, expected, x)
227227
self.assertEqual(got, expected, msg)

Objects/longobject.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static PyLongObject *long_normalize(PyLongObject *);
3535
static PyLongObject *mul1(PyLongObject *, wdigit);
3636
static PyLongObject *muladd1(PyLongObject *, wdigit, wdigit);
3737
static PyLongObject *divrem1(PyLongObject *, digit, digit *);
38-
static PyObject *long_format(PyObject *aa, int base, int addL);
38+
static PyObject *long_format(PyObject *aa, int base);
3939

4040
#define SIGCHECK(PyTryBlock) \
4141
if (--_Py_Ticker < 0) { \
@@ -1198,7 +1198,7 @@ divrem1(PyLongObject *a, digit n, digit *prem)
11981198
If base is 8 or 16, add the proper prefix '0' or '0x'. */
11991199

12001200
static PyObject *
1201-
long_format(PyObject *aa, int base, int addL)
1201+
long_format(PyObject *aa, int base)
12021202
{
12031203
register PyLongObject *a = (PyLongObject *)aa;
12041204
PyStringObject *str;
@@ -1222,14 +1222,12 @@ long_format(PyObject *aa, int base, int addL)
12221222
++bits;
12231223
i >>= 1;
12241224
}
1225-
i = 5 + (addL ? 1 : 0) + (size_a*SHIFT + bits-1) / bits;
1225+
i = 5 + (size_a*SHIFT + bits-1) / bits;
12261226
str = (PyStringObject *) PyString_FromStringAndSize((char *)0, i);
12271227
if (str == NULL)
12281228
return NULL;
12291229
p = PyString_AS_STRING(str) + i;
12301230
*p = '\0';
1231-
if (addL)
1232-
*--p = 'L';
12331231
if (a->ob_size < 0)
12341232
sign = '-';
12351233

@@ -1890,13 +1888,7 @@ long_dealloc(PyObject *v)
18901888
static PyObject *
18911889
long_repr(PyObject *v)
18921890
{
1893-
return long_format(v, 10, 1);
1894-
}
1895-
1896-
static PyObject *
1897-
long_str(PyObject *v)
1898-
{
1899-
return long_format(v, 10, 0);
1891+
return long_format(v, 10);
19001892
}
19011893

19021894
static int
@@ -3255,13 +3247,13 @@ long_float(PyObject *v)
32553247
static PyObject *
32563248
long_oct(PyObject *v)
32573249
{
3258-
return long_format(v, 8, 1);
3250+
return long_format(v, 8);
32593251
}
32603252

32613253
static PyObject *
32623254
long_hex(PyObject *v)
32633255
{
3264-
return long_format(v, 16, 1);
3256+
return long_format(v, 16);
32653257
}
32663258

32673259
static PyObject *
@@ -3407,7 +3399,7 @@ PyTypeObject PyLong_Type = {
34073399
0, /* tp_as_mapping */
34083400
(hashfunc)long_hash, /* tp_hash */
34093401
0, /* tp_call */
3410-
long_str, /* tp_str */
3402+
0, /* tp_str */
34113403
PyObject_GenericGetAttr, /* tp_getattro */
34123404
0, /* tp_setattro */
34133405
0, /* tp_as_buffer */

0 commit comments

Comments
 (0)