mirror of https://github.com/python/cpython
repr() of a long int no longer produces a trailing 'L'.
More unit tests probably need fixing; later...
This commit is contained in:
parent
f43127862d
commit
d2dbecb4ae
|
@ -196,7 +196,7 @@ class LongTest(unittest.TestCase):
|
||||||
def slow_format(self, x, base):
|
def slow_format(self, x, base):
|
||||||
if (x, base) == (0, 8):
|
if (x, base) == (0, 8):
|
||||||
# this is an oddball!
|
# this is an oddball!
|
||||||
return "0L"
|
return "0"
|
||||||
digits = []
|
digits = []
|
||||||
sign = 0
|
sign = 0
|
||||||
if x < 0:
|
if x < 0:
|
||||||
|
@ -208,7 +208,7 @@ class LongTest(unittest.TestCase):
|
||||||
digits = digits or [0]
|
digits = digits or [0]
|
||||||
return '-'[:sign] + \
|
return '-'[:sign] + \
|
||||||
{8: '0', 10: '', 16: '0x'}[base] + \
|
{8: '0', 10: '', 16: '0x'}[base] + \
|
||||||
"".join(map(lambda i: "0123456789abcdef"[i], digits)) + "L"
|
"".join(map(lambda i: "0123456789abcdef"[i], digits))
|
||||||
|
|
||||||
def check_format_1(self, x):
|
def check_format_1(self, x):
|
||||||
for base, mapper in (8, oct), (10, repr), (16, hex):
|
for base, mapper in (8, oct), (10, repr), (16, hex):
|
||||||
|
@ -221,7 +221,7 @@ class LongTest(unittest.TestCase):
|
||||||
# str() has to be checked a little differently since there's no
|
# str() has to be checked a little differently since there's no
|
||||||
# trailing "L"
|
# trailing "L"
|
||||||
got = str(x)
|
got = str(x)
|
||||||
expected = self.slow_format(x, 10)[:-1]
|
expected = self.slow_format(x, 10)
|
||||||
msg = Frm("%s returned %r but expected %r for %r",
|
msg = Frm("%s returned %r but expected %r for %r",
|
||||||
mapper.__name__, got, expected, x)
|
mapper.__name__, got, expected, x)
|
||||||
self.assertEqual(got, expected, msg)
|
self.assertEqual(got, expected, msg)
|
||||||
|
|
|
@ -35,7 +35,7 @@ static PyLongObject *long_normalize(PyLongObject *);
|
||||||
static PyLongObject *mul1(PyLongObject *, wdigit);
|
static PyLongObject *mul1(PyLongObject *, wdigit);
|
||||||
static PyLongObject *muladd1(PyLongObject *, wdigit, wdigit);
|
static PyLongObject *muladd1(PyLongObject *, wdigit, wdigit);
|
||||||
static PyLongObject *divrem1(PyLongObject *, digit, digit *);
|
static PyLongObject *divrem1(PyLongObject *, digit, digit *);
|
||||||
static PyObject *long_format(PyObject *aa, int base, int addL);
|
static PyObject *long_format(PyObject *aa, int base);
|
||||||
|
|
||||||
#define SIGCHECK(PyTryBlock) \
|
#define SIGCHECK(PyTryBlock) \
|
||||||
if (--_Py_Ticker < 0) { \
|
if (--_Py_Ticker < 0) { \
|
||||||
|
@ -1198,7 +1198,7 @@ divrem1(PyLongObject *a, digit n, digit *prem)
|
||||||
If base is 8 or 16, add the proper prefix '0' or '0x'. */
|
If base is 8 or 16, add the proper prefix '0' or '0x'. */
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
long_format(PyObject *aa, int base, int addL)
|
long_format(PyObject *aa, int base)
|
||||||
{
|
{
|
||||||
register PyLongObject *a = (PyLongObject *)aa;
|
register PyLongObject *a = (PyLongObject *)aa;
|
||||||
PyStringObject *str;
|
PyStringObject *str;
|
||||||
|
@ -1222,14 +1222,12 @@ long_format(PyObject *aa, int base, int addL)
|
||||||
++bits;
|
++bits;
|
||||||
i >>= 1;
|
i >>= 1;
|
||||||
}
|
}
|
||||||
i = 5 + (addL ? 1 : 0) + (size_a*SHIFT + bits-1) / bits;
|
i = 5 + (size_a*SHIFT + bits-1) / bits;
|
||||||
str = (PyStringObject *) PyString_FromStringAndSize((char *)0, i);
|
str = (PyStringObject *) PyString_FromStringAndSize((char *)0, i);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p = PyString_AS_STRING(str) + i;
|
p = PyString_AS_STRING(str) + i;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (addL)
|
|
||||||
*--p = 'L';
|
|
||||||
if (a->ob_size < 0)
|
if (a->ob_size < 0)
|
||||||
sign = '-';
|
sign = '-';
|
||||||
|
|
||||||
|
@ -1890,13 +1888,7 @@ long_dealloc(PyObject *v)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
long_repr(PyObject *v)
|
long_repr(PyObject *v)
|
||||||
{
|
{
|
||||||
return long_format(v, 10, 1);
|
return long_format(v, 10);
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
long_str(PyObject *v)
|
|
||||||
{
|
|
||||||
return long_format(v, 10, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -3255,13 +3247,13 @@ long_float(PyObject *v)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
long_oct(PyObject *v)
|
long_oct(PyObject *v)
|
||||||
{
|
{
|
||||||
return long_format(v, 8, 1);
|
return long_format(v, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
long_hex(PyObject *v)
|
long_hex(PyObject *v)
|
||||||
{
|
{
|
||||||
return long_format(v, 16, 1);
|
return long_format(v, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3407,7 +3399,7 @@ PyTypeObject PyLong_Type = {
|
||||||
0, /* tp_as_mapping */
|
0, /* tp_as_mapping */
|
||||||
(hashfunc)long_hash, /* tp_hash */
|
(hashfunc)long_hash, /* tp_hash */
|
||||||
0, /* tp_call */
|
0, /* tp_call */
|
||||||
long_str, /* tp_str */
|
0, /* tp_str */
|
||||||
PyObject_GenericGetAttr, /* tp_getattro */
|
PyObject_GenericGetAttr, /* tp_getattro */
|
||||||
0, /* tp_setattro */
|
0, /* tp_setattro */
|
||||||
0, /* tp_as_buffer */
|
0, /* tp_as_buffer */
|
||||||
|
|
Loading…
Reference in New Issue